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(listbox): use filter tag #5952

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 2 additions & 30 deletions packages/components/docs/sass.md
Original file line number Diff line number Diff line change
Expand Up @@ -7229,7 +7229,6 @@ $inverse-01: if(
- [button [mixin]](#button-mixin)
- [checkbox [mixin]](#checkbox-mixin)
- [content-switcher [mixin]](#content-switcher-mixin)
- [listbox [mixin]](#listbox-mixin)
- [inline-notifications [mixin]](#inline-notifications-mixin)
- [toast-notifications [mixin]](#toast-notifications-mixin)
- [progress-indicator [mixin]](#progress-indicator-mixin)
Expand Down Expand Up @@ -7262,7 +7261,6 @@ $inverse-02: if(
- **Type**: `{undefined}`
- **Used by**:
- [carbon--theme [mixin]](#carbon--theme-mixin)
- [listbox [mixin]](#listbox-mixin)
- [inline-notifications [mixin]](#inline-notifications-mixin)
- [toast-notifications [mixin]](#toast-notifications-mixin)
- [tags [mixin]](#tags-mixin)
Expand Down Expand Up @@ -7717,7 +7715,6 @@ $hover-secondary: if(
- **Used by**:
- [carbon--theme [mixin]](#carbon--theme-mixin)
- [button [mixin]](#button-mixin)
- [listbox [mixin]](#listbox-mixin)

### ✅active-secondary [variable]

Expand Down Expand Up @@ -18892,42 +18889,20 @@ List box styles
}

// Modifier for a selection to show that multiple selections have been made
.#{$prefix}--list-box__selection--multi {
@include type-style('label-01');
.#{$prefix}--tag.#{$prefix}--list-box__selection--multi {
position: static;
display: flex;
align-items: center;
justify-content: space-between;
padding: 0;
background-color: $inverse-02;
height: rem(24px);
width: auto;
color: $inverse-01;
line-height: 0;
padding: rem(8px);
padding-right: rem(2px); // Align with hover circle of X button
margin: 0;
margin-right: rem(10px);
border-radius: rem(12px);
}

.#{$prefix}--list-box__selection--multi > svg {
fill: $inverse-01;
margin-left: rem(4px);
width: rem(20px);
height: rem(20px);
padding: rem(2px);
}

.#{$prefix}--list-box__selection--multi > svg:hover {
border-radius: 50%;
background-color: $hover-secondary;
}

.#{$prefix}--list-box__selection--multi:focus,
.#{$prefix}--list-box__selection--multi:hover {
outline: none;
}

// Descendant of a `list-box` that displays a list of options to select
.#{$prefix}--list-box__menu {
@include box-shadow();
Expand Down Expand Up @@ -19201,9 +19176,6 @@ List box styles
- [carbon--spacing-05 [variable]](#carbon--spacing-05-variable)
- [icon-01 [variable]](#icon-01-variable)
- [icon-02 [variable]](#icon-02-variable)
- [inverse-02 [variable]](#inverse-02-variable)
- [inverse-01 [variable]](#inverse-01-variable)
- [hover-secondary [variable]](#hover-secondary-variable)
- [ui-01 [variable]](#ui-01-variable)
- [text-02 [variable]](#text-02-variable)
- [selected-ui [variable]](#selected-ui-variable)
Expand Down
27 changes: 5 additions & 22 deletions packages/components/src/components/list-box/_list-box.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
@import '../../globals/scss/helper-mixins';
@import '../../globals/scss/layout';
@import '../../globals/scss/vendor/@carbon/elements/scss/import-once/import-once';
@import '../tag/tag';
@import '../../globals/scss/css--reset';

/// @type Number
Expand Down Expand Up @@ -388,40 +389,22 @@ $list-box-menu-width: rem(300px);
}

// Modifier for a selection to show that multiple selections have been made
.#{$prefix}--list-box__selection--multi {
@include type-style('label-01');
.#{$prefix}--tag.#{$prefix}--list-box__selection--multi {
position: static;
display: flex;
align-items: center;
justify-content: space-between;
padding: 0;
background-color: $inverse-02;
height: rem(24px);
width: auto;
color: $inverse-01;
line-height: 0;
padding: rem(8px);
padding-right: rem(2px); // Align with hover circle of X button
margin: 0;
margin-right: rem(10px);
border-radius: rem(12px);
}

.#{$prefix}--list-box__selection--multi > svg {
fill: $inverse-01;
margin-left: rem(4px);
width: rem(20px);
height: rem(20px);
padding: rem(2px);
}

.#{$prefix}--list-box__selection--multi > svg:hover {
border-radius: 50%;
background-color: $hover-secondary;
}

.#{$prefix}--list-box__selection--multi:focus,
.#{$prefix}--list-box__selection--multi:hover {
outline: none;
.#{$prefix}--tag.#{$prefix}--list-box__selection--disabled {
@include tag-theme($disabled-02, $disabled-03);
}

// Descendant of a `list-box` that displays a list of options to select
Expand Down
15 changes: 7 additions & 8 deletions packages/react/src/components/ListBox/ListBoxSelection.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
import cx from 'classnames';
import React from 'react';
import PropTypes from 'prop-types';
import { Close16 } from '@carbon/icons-react';
import { settings } from 'carbon-components';
import { match, keys } from '../../internal/keyboard';
import Tag from '../Tag';

const { prefix } = settings;

Expand All @@ -26,8 +26,8 @@ const ListBoxSelection = ({
disabled,
}) => {
const className = cx(`${prefix}--list-box__selection`, {
[`${prefix}--tag--filter`]: selectionCount,
[`${prefix}--list-box__selection--multi`]: selectionCount,
[`${prefix}--list-box__selection--disabled`]: disabled,
});
const handleOnClick = event => {
event.stopPropagation();
Expand All @@ -49,17 +49,16 @@ const ListBoxSelection = ({
};
const description = selectionCount ? t('clear.all') : t('clear.selection');
return (
<div
role="button"
<Tag
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can add the disabled prop here so we can get the correct styles when the multiselect is disabled

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking that too and compared it to the current implementation where the tag styling is not changed on disable.

Personally I would also prefer to have the tag disabled since otherwise it really stands out. Do you if there was a reason behind the current implementation, like keeping it well readable for accessibility maybe?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it looks like there is a slight color change on the disabled tag svg in the current multiselect, but I'm not sure if it should look like the standalone disabled tag styles cc @laurenmrice

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just as a reference: this is how it would look when the tag enters disabled state as well:
image

Copy link
Member

@laurenmrice laurenmrice Apr 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me make a spec for this 👍🏻, will get back to you shortly

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what we can do for a selected-disabled state.

tags

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick specs, @laurenmrice 👍
I updated the tag color for the disabled state accordingly, you can check it out in the deploy preview: https://5eaae7cd3ab6150007c0340b--carbon-components-react.netlify.app/?path=/story/multiselect--default

className={className}
tabIndex={disabled ? -1 : 0}
type="high-contrast"
filter
onClose={handleOnClick}
onClick={handleOnClick}
onKeyDown={handleOnKeyDown}
aria-label="Clear Selection"
title={description}>
{selectionCount}
<Close16 />
</div>
</Tag>
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,39 +16,58 @@ exports[`ListBoxField should render 1`] = `
clearSelection={[MockFunction]}
translateWithId={[Function]}
>
<div
aria-label="Clear Selection"
<Tag
className="bx--list-box__selection"
filter={true}
onClick={[Function]}
onClose={[Function]}
onKeyDown={[Function]}
role="button"
tabIndex={0}
title="Clear selected item"
type="high-contrast"
>
<ForwardRef(Close16)>
<Icon
height={16}
preserveAspectRatio="xMidYMid meet"
viewBox="0 0 32 32"
width={16}
xmlns="http://www.w3.org/2000/svg"
<div
aria-label="Clear selected item undefined"
className="bx--tag bx--list-box__selection bx--tag--filter bx--tag--high-contrast"
id="tag-1"
onClick={[Function]}
onKeyDown={[Function]}
>
<span
className="bx--tag__label"
>
<svg
aria-hidden={true}
focusable="false"
height={16}
preserveAspectRatio="xMidYMid meet"
viewBox="0 0 32 32"
width={16}
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M24 9.4L22.6 8 16 14.6 9.4 8 8 9.4 14.6 16 8 22.6 9.4 24 16 17.4 22.6 24 24 22.6 17.4 16 24 9.4z"
/>
</svg>
</Icon>
</ForwardRef(Close16)>
</div>
High-Contrast
</span>
<button
aria-labelledby="tag-1"
className="bx--tag__close-icon"
onClick={[Function]}
>
<ForwardRef(Close16)>
<Icon
height={16}
preserveAspectRatio="xMidYMid meet"
viewBox="0 0 32 32"
width={16}
xmlns="http://www.w3.org/2000/svg"
>
<svg
aria-hidden={true}
focusable="false"
height={16}
preserveAspectRatio="xMidYMid meet"
viewBox="0 0 32 32"
width={16}
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M24 9.4L22.6 8 16 14.6 9.4 8 8 9.4 14.6 16 8 22.6 9.4 24 16 17.4 22.6 24 24 22.6 17.4 16 24 9.4z"
/>
</svg>
</Icon>
</ForwardRef(Close16)>
</button>
</div>
</Tag>
</ListBoxSelection>
</div>
</ListBoxField>
Expand All @@ -72,39 +91,58 @@ exports[`ListBoxField should set \`aria-owns\` based when expanded 1`] = `
clearSelection={[MockFunction]}
translateWithId={[Function]}
>
<div
aria-label="Clear Selection"
<Tag
className="bx--list-box__selection"
filter={true}
onClick={[Function]}
onClose={[Function]}
onKeyDown={[Function]}
role="button"
tabIndex={0}
title="Clear selected item"
type="high-contrast"
>
<ForwardRef(Close16)>
<Icon
height={16}
preserveAspectRatio="xMidYMid meet"
viewBox="0 0 32 32"
width={16}
xmlns="http://www.w3.org/2000/svg"
<div
aria-label="Clear selected item undefined"
className="bx--tag bx--list-box__selection bx--tag--filter bx--tag--high-contrast"
id="tag-3"
onClick={[Function]}
onKeyDown={[Function]}
>
<span
className="bx--tag__label"
>
High-Contrast
</span>
<button
aria-labelledby="tag-3"
className="bx--tag__close-icon"
onClick={[Function]}
>
<svg
aria-hidden={true}
focusable="false"
height={16}
preserveAspectRatio="xMidYMid meet"
viewBox="0 0 32 32"
width={16}
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M24 9.4L22.6 8 16 14.6 9.4 8 8 9.4 14.6 16 8 22.6 9.4 24 16 17.4 22.6 24 24 22.6 17.4 16 24 9.4z"
/>
</svg>
</Icon>
</ForwardRef(Close16)>
</div>
<ForwardRef(Close16)>
<Icon
height={16}
preserveAspectRatio="xMidYMid meet"
viewBox="0 0 32 32"
width={16}
xmlns="http://www.w3.org/2000/svg"
>
<svg
aria-hidden={true}
focusable="false"
height={16}
preserveAspectRatio="xMidYMid meet"
viewBox="0 0 32 32"
width={16}
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M24 9.4L22.6 8 16 14.6 9.4 8 8 9.4 14.6 16 8 22.6 9.4 24 16 17.4 22.6 24 24 22.6 17.4 16 24 9.4z"
/>
</svg>
</Icon>
</ForwardRef(Close16)>
</button>
</div>
</Tag>
</ListBoxSelection>
</div>
</ListBoxField>
Expand Down
Loading