Skip to content

Commit 9531c69

Browse files
Divyue30597Gururajj77heloiselui
authored
Fix(multi select) change for navigating multi select item in multi select web component (#21013)
* fix(multi-select): change for multi-select-item navigation * fix(multi-select): updates the logic for keyboard navigation --------- Co-authored-by: Gururaj J <[email protected]> Co-authored-by: Heloise Lui <[email protected]>
1 parent 6e1243f commit 9531c69

File tree

1 file changed

+5
-32
lines changed

1 file changed

+5
-32
lines changed

packages/web-components/src/components/multi-select/multi-select.ts

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,7 @@ import { property, query } from 'lit/decorators.js';
1010
import { classMap } from 'lit/directives/class-map.js';
1111
import { prefix } from '../../globals/settings';
1212
import Close16 from '@carbon/icons/es/close/16.js';
13-
import {
14-
filter,
15-
forEach,
16-
indexOf,
17-
} from '../../globals/internal/collection-helpers';
13+
import { filter, forEach } from '../../globals/internal/collection-helpers';
1814
import CDSDropdown, {
1915
DROPDOWN_KEYBOARD_ACTION,
2016
DROPDOWN_TYPE,
@@ -534,34 +530,11 @@ class CDSMultiSelect extends CDSDropdown {
534530
* @param direction `-1` to navigate backward, `1` to navigate forward.
535531
*/
536532
protected _navigate(direction: number) {
537-
if (!this.filterable) {
538-
super._navigate(direction);
539-
this._triggerNode.classList.add('no-focus-style');
540-
} else {
541-
// only navigate through remaining item
542-
const constructor = this.constructor as typeof CDSMultiSelect;
543-
const items = this.querySelectorAll(constructor.selectorItemResults);
544-
const highlightedItem = this.querySelector(
545-
constructor.selectorItemHighlighted
546-
);
547-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- https://github.com/carbon-design-system/carbon/issues/20452
548-
const highlightedIndex = indexOf(items, highlightedItem!);
549-
550-
let nextIndex = highlightedIndex + direction;
551-
552-
if (items[nextIndex]?.hasAttribute('disabled')) {
553-
nextIndex += direction;
554-
}
555-
if (nextIndex < 0) {
556-
nextIndex = items.length - 1;
557-
}
558-
if (nextIndex >= items.length) {
559-
nextIndex = 0;
560-
}
561-
forEach(items, (item, i) => {
562-
(item as CDSMultiSelectItem).highlighted = i === nextIndex;
563-
});
533+
super._navigate(direction);
534+
if (this.filterable) {
564535
this.setAttribute('item-clicked', '');
536+
} else {
537+
this._triggerNode.classList.add('no-focus-style');
565538
}
566539
}
567540

0 commit comments

Comments
 (0)