Skip to content

Commit

Permalink
feat(Tag): add pointer on hover if component is interactive (#7839)
Browse files Browse the repository at this point in the history
* feat(Tag): add pointer on hover if component is interactive

* docs(Tag): add interactive tag example

* fix(tag): add disabled interactive cursor

* feat(tag): dynamically apply hover color for interactive tags

* feat(tag): add interactive tag focus outline

* fix(Tag): render button when nonfilter tag is interactive

* fix(Tag): make interactive and filter tags mutually exclusive

* fix(tag): add transitions to interactive tag
  • Loading branch information
emyarod authored Mar 3, 2021
1 parent 8b207f1 commit d944ac5
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 32 deletions.
1 change: 1 addition & 0 deletions packages/components/src/components/tag/_mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
color: $text-color;
background-color: $bg-color;

&.#{$prefix}--tag--interactive,
.#{$prefix}--tag__close-icon {
&:hover {
background-color: $filter-hover-color;
Expand Down
16 changes: 15 additions & 1 deletion packages/components/src/components/tag/_tag.scss
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@
}

.#{$prefix}--tag--disabled,
.#{$prefix}--tag--filter.#{$prefix}--tag--disabled {
.#{$prefix}--tag--filter.#{$prefix}--tag--disabled,
.#{$prefix}--tag--interactive.#{$prefix}--tag--disabled {
@include tag-theme($disabled-01, $disabled-02);

&:hover {
Expand All @@ -146,6 +147,15 @@
text-overflow: ellipsis;
}

.#{$prefix}--tag--interactive:focus {
outline: none;
box-shadow: inset 0 0 0 1px $focus;
}

.#{$prefix}--tag--interactive:hover {
cursor: pointer;
}

// tags used for filtering
.#{$prefix}--tag--filter {
padding-top: 0;
Expand All @@ -158,6 +168,10 @@
}
}

.#{$prefix}--tag--interactive {
transition: background-color $duration--fast-01 motion(entrance, productive);
}

.#{$prefix}--tag__close-icon {
display: flex;
flex-shrink: 0;
Expand Down
14 changes: 11 additions & 3 deletions packages/react/src/components/Tag/Tag-story.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,17 @@ export default {
};

export const _Default = () => (
<Tag className="some-class" {...props.regular()}>
{text('Content (children)', 'This is a tag')}
</Tag>
<>
<Tag className="some-class" {...props.regular()}>
{text('Content (children)', 'This is a tag')}
</Tag>
<Tag
className="some-class"
{...props.regular()}
onClick={action('onClick')}>
This is an interactive tag
</Tag>
</>
);

_Default.parameters = {
Expand Down
63 changes: 35 additions & 28 deletions packages/react/src/components/Tag/Tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const Tag = ({
[`${prefix}--tag--filter`]: filter,
[`${prefix}--tag--${size}`]: size,
[`${prefix}--tag--${type}`]: type,
[`${prefix}--tag--interactive`]: other.onClick && !filter,
});
const handleClose = (event) => {
if (onClose) {
Expand All @@ -55,33 +56,39 @@ const Tag = ({
}
};

return filter ? (
<div
className={tagClasses}
aria-label={
title !== undefined
? `${title} ${children}`
: `Clear filter ${children}`
}
id={tagId}
{...other}>
<span
className={`${prefix}--tag__label`}
title={typeof children === 'string' ? children : null}>
{children !== null && children !== undefined ? children : TYPES[type]}
</span>
<button
type="button"
className={`${prefix}--tag__close-icon`}
onClick={handleClose}
disabled={disabled}
aria-labelledby={tagId}
title={title}>
<Close16 />
</button>
</div>
) : (
<div className={tagClasses} id={tagId} {...other}>
if (filter) {
return (
<div
className={tagClasses}
aria-label={
title !== undefined
? `${title} ${children}`
: `Clear filter ${children}`
}
id={tagId}
{...other}>
<span
className={`${prefix}--tag__label`}
title={typeof children === 'string' ? children : null}>
{children !== null && children !== undefined ? children : TYPES[type]}
</span>
<button
type="button"
className={`${prefix}--tag__close-icon`}
onClick={handleClose}
disabled={disabled}
aria-labelledby={tagId}
title={title}>
<Close16 />
</button>
</div>
);
}

const ComponentTag = other.onClick ? 'button' : 'div';

return (
<ComponentTag className={tagClasses} id={tagId} {...other}>
{CustomIconElement ? (
<div className={`${prefix}--tag__custom-icon`}>
<CustomIconElement />
Expand All @@ -92,7 +99,7 @@ const Tag = ({
<span title={typeof children === 'string' ? children : null}>
{children !== null && children !== undefined ? children : TYPES[type]}
</span>
</div>
</ComponentTag>
);
};

Expand Down

0 comments on commit d944ac5

Please sign in to comment.