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(multiselect): 5880-multiselect-active-descendent #7908

Merged
merged 20 commits into from
Mar 18, 2021
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
50382e9
fix(multiselect): 5880-multiselect-active-descendent
andreancardona Feb 25, 2021
17c73be
fix(multiselect): adds visually hidden description
andreancardona Mar 1, 2021
47bd5a5
Merge branch 'master' into 5880-multiselect-active-descendent-violation
andreancardona Mar 1, 2021
cf44869
chore: update ListBox test
jnm2377 Mar 2, 2021
155f707
Merge branch 'master' into 5880-multiselect-active-descendent-violation
andreancardona Mar 2, 2021
7cee635
feat: add delete key
jnm2377 Mar 2, 2021
3ed55a8
fix: use keys/match for evt listener
jnm2377 Mar 2, 2021
92ba350
Merge branch 'master' into 5880-multiselect-active-descendent-violation
jnm2377 Mar 6, 2021
6a42280
Merge branch 'master' into 5880-multiselect-active-descendent-violation
jnm2377 Mar 8, 2021
58d91c1
Merge branch 'main' of github.com:carbon-design-system/carbon into 58…
jnm2377 Mar 15, 2021
86c2f60
fix: support backspace or delete
jnm2377 Mar 15, 2021
5d932ba
fix: add prop for clear selection text
jnm2377 Mar 15, 2021
9a33305
chore: update tests
jnm2377 Mar 15, 2021
24faa79
fix: combine title with delete description
jnm2377 Mar 16, 2021
c0a0e63
chore: update tests
jnm2377 Mar 16, 2021
9f22087
Merge branch 'main' into 5880-multiselect-active-descendent-violation
jnm2377 Mar 16, 2021
adc1a98
Merge branch 'main' into 5880-multiselect-active-descendent-violation
jnm2377 Mar 17, 2021
42f3263
Merge branch 'main' into 5880-multiselect-active-descendent-violation
dakahn Mar 18, 2021
468af40
Merge branch 'main' into 5880-multiselect-active-descendent-violation
kodiakhq[bot] Mar 18, 2021
443707a
Merge branch 'main' into 5880-multiselect-active-descendent-violation
kodiakhq[bot] Mar 18, 2021
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
2 changes: 2 additions & 0 deletions packages/react/src/components/ListBox/ListBoxSelection.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ const ListBoxSelection = ({
onKeyDown={handleOnKeyDown}
disabled={disabled}
aria-label={t('clear.all')}
aria-hidden={true}
title={description}>
<Close16 />
</div>
Expand All @@ -88,6 +89,7 @@ const ListBoxSelection = ({
onClick={handleOnClick}
onKeyDown={handleOnKeyDown}
aria-label={description}
aria-hidden={true}
title={description}>
{selectionCount}
<Close16 />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ exports[`ListBoxField should render 1`] = `
translateWithId={[Function]}
>
<div
aria-hidden={true}
aria-label="Clear selected item"
className="bx--list-box__selection"
onClick={[Function]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ exports[`ListBoxSelection should render 1`] = `
}
>
<div
aria-hidden={true}
aria-label="translation"
className="bx--list-box__selection"
onClick={[Function]}
Expand Down Expand Up @@ -115,6 +116,7 @@ exports[`ListBoxSelection should render 2`] = `
3
</span>
<div
aria-hidden={true}
aria-label="translation"
className="bx--tag__close-icon"
onClick={[Function]}
Expand Down
19 changes: 18 additions & 1 deletion packages/react/src/components/MultiSelect/MultiSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { useSelection } from '../../internal/Selection';
import setupGetInstanceId from '../../tools/setupGetInstanceId';
import { mapDownshiftProps } from '../../tools/createPropAdapter';
import mergeRefs from '../../tools/mergeRefs';
import { keys, match } from '../../internal/keyboard';

const { prefix } = settings;
const noop = () => {};
Expand Down Expand Up @@ -193,6 +194,13 @@ const MultiSelect = React.forwardRef(function MultiSelect(
}
}

const onKeyDown = (e) => {
if (match(e, keys.Delete) && !disabled) {
clearSelection();
e.stopPropagation();
}
};

const toggleButtonProps = getToggleButtonProps();

return (
Expand Down Expand Up @@ -222,13 +230,22 @@ const MultiSelect = React.forwardRef(function MultiSelect(
className={`${prefix}--list-box__invalid-icon ${prefix}--list-box__invalid-icon--warning`}
/>
)}
{selectedItems.length > 0 && (
<span
className={`${prefix}--visually-hidden`}
id={`clear-button-label${id}`}>
To clear selection, press Delete
jnm2377 marked this conversation as resolved.
Show resolved Hide resolved
</span>
)}
<button
aria-describedby={`clear-button-label${id}`}
type="button"
className={`${prefix}--list-box__field`}
disabled={disabled}
aria-disabled={disabled}
{...toggleButtonProps}
ref={mergeRefs(toggleButtonProps.ref, ref)}>
ref={mergeRefs(toggleButtonProps.ref, ref)}
onKeyDown={onKeyDown}>
{selectedItems.length > 0 && (
<ListBox.Selection
clearSelection={!disabled ? clearSelection : noop}
Expand Down
6 changes: 6 additions & 0 deletions packages/react/src/internal/keyboard/keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,9 @@ export const ArrowDown = {
which: 40,
keyCode: 40,
};

export const Delete = {
key: 'Delete',
which: 8,
keyCode: 8,
jnm2377 marked this conversation as resolved.
Show resolved Hide resolved
};