Skip to content

Commit

Permalink
fix(FilterableMultiselect): remove clear, tag from tab order
Browse files Browse the repository at this point in the history
  • Loading branch information
tw15egan committed Feb 17, 2023
1 parent b7ac696 commit ca262ed
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 21 deletions.
1 change: 0 additions & 1 deletion packages/react/src/components/ListBox/ListBoxSelection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import cx from 'classnames';
import React from 'react';
import PropTypes from 'prop-types';
import { Close } from '@carbon/icons-react';
import { match, keys } from '../../internal/keyboard';
import { usePrefix } from '../../internal/usePrefix';
import { KeyboardEvent, MouseEvent } from 'react';

Expand Down
22 changes: 2 additions & 20 deletions packages/react/src/components/ListBox/next/ListBoxSelection.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import cx from 'classnames';
import React from 'react';
import PropTypes from 'prop-types';
import { Close } from '@carbon/icons-react';
import { match, keys } from '../../../internal/keyboard';
import { usePrefix } from '../../../internal/usePrefix';

/**
Expand Down Expand Up @@ -51,21 +50,6 @@ function ListBoxSelection({
}
}

function onKeyDown(event) {
event.stopPropagation();
if (disabled) {
return;
}

// When a user hits ENTER, we'll clear the selection
if (match(event, keys.Enter)) {
clearSelection(event);
if (onClearSelection) {
onClearSelection(event);
}
}
}

if (selectionCount) {
return (
<div className={tagClasses}>
Expand All @@ -77,8 +61,7 @@ function ListBoxSelection({
className={`${prefix}--tag__close-icon`}
disabled={disabled}
onClick={onClick}
onKeyDown={onKeyDown}
tabIndex={disabled ? -1 : 0}
tabIndex={-1}
title={description}
type="button">
<Close />
Expand All @@ -94,8 +77,7 @@ function ListBoxSelection({
className={className}
disabled={disabled}
onClick={onClick}
onKeyDown={onKeyDown}
tabIndex={disabled ? -1 : 0}
tabIndex={-1}
title={description}
type="button">
<Close />
Expand Down
16 changes: 16 additions & 0 deletions packages/react/src/components/MultiSelect/FilterableMultiSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,22 @@ const FilterableMultiSelect = React.forwardRef(function FilterableMultiSelect(
event.stopPropagation();
}

if (!disabled) {
if (match(event, keys.Delete) || match(event, keys.Escape)) {
if (isOpen) {
handleOnMenuChange(true);
event.stopPropagation();
} else if (!isOpen) {
clearInputValue();
event.stopPropagation();
if (event.target.value === '') {
clearSelection();
event.stopPropagation();
}
}
}
}

if (match(event, keys.Tab)) {
handleOnMenuChange(false);
}
Expand Down

0 comments on commit ca262ed

Please sign in to comment.