Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Tag): added new prop titleText to specify title on clear #4163

Merged
1 change: 1 addition & 0 deletions packages/react/src/components/Tag/Tag-story.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const props = {
),
disabled: boolean('Disabled (disabled)', false),
role: 'listitem',
titleText: 'Clear Selection',
}),
filter() {
return { ...this.regular(), onClick: action('onClick') };
Expand Down
19 changes: 16 additions & 3 deletions packages/react/src/components/Tag/Tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,15 @@ const TYPES = {
'warm-gray': 'Warm-Gray',
};

const Tag = ({ children, className, type, filter, disabled, ...other }) => {
const Tag = ({
children,
className,
type,
filter,
titleText,
disabled,
...other
}) => {
const tagClass = `${prefix}--tag--${type}`;
const tagClasses = classNames(`${prefix}--tag`, tagClass, className, {
[`${prefix}--tag--disabled`]: disabled,
Expand All @@ -35,11 +43,11 @@ const Tag = ({ children, className, type, filter, disabled, ...other }) => {
return filter ? (
<span
className={tagClasses}
title="Clear filter"
title={titleText ? titleText : 'Clear filter'}
tabIndex="0" // eslint-disable-line jsx-a11y/no-noninteractive-tabindex
{...other}>
{children !== null && children !== undefined ? children : TYPES[type]}
<Close16 aria-label="Clear filter" />
<Close16 aria-label={titleText ? titleText : 'Clear filter'} />
</span>
) : (
<span className={tagClasses} {...other}>
Expand Down Expand Up @@ -73,6 +81,11 @@ Tag.propTypes = {
* Determine if <Tag> is a filter/chip
*/
filter: PropTypes.bool,

/**
* Text to show on clear filters
*/
titleText: PropTypes.string,
};

export const types = Object.keys(TYPES);
Expand Down