Skip to content

Commit

Permalink
fix: filterable multiselect search issue
Browse files Browse the repository at this point in the history
  • Loading branch information
riddhybansal committed Jun 10, 2024
1 parent 5663eaa commit 05be270
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ const FilterableMultiSelect = React.forwardRef(function FilterableMultiSelect<
if (changes.isOpen && !isOpen) {
setTopItems(controlledSelectedItems);
}

console.log(type);
switch (type) {
case InputKeyDownEnter:
if (changes.selectedItem && changes.selectedItem.disabled !== true) {
Expand All @@ -465,6 +465,8 @@ const FilterableMultiSelect = React.forwardRef(function FilterableMultiSelect<
return changes;
case InputBlur:
case InputKeyDownEscape:
setInputFocused(false);
setInputValue('');
setIsOpen(false);
return changes;
case FunctionToggleMenu:
Expand All @@ -477,6 +479,7 @@ const FilterableMultiSelect = React.forwardRef(function FilterableMultiSelect<
if (onInputValueChange) {
onInputValueChange(changes.inputValue);
}
console.log('valueee');
setInputValue(changes.inputValue ?? '');
setIsOpen(true);
return changes;
Expand Down Expand Up @@ -548,6 +551,7 @@ const FilterableMultiSelect = React.forwardRef(function FilterableMultiSelect<
});

function clearInputValue(event?: KeyboardEvent | undefined) {
console.log('clear');
const value = textInput.current?.value;
if (value?.length === 1 || (event && match(event, keys.Escape))) {
setInputValue('');
Expand Down Expand Up @@ -659,10 +663,6 @@ const FilterableMultiSelect = React.forwardRef(function FilterableMultiSelect<
}
},
onFocus: () => setInputFocused(true),
onBlur() {
setInputFocused(false);
setInputValue('');
},
})
);
const menuProps = getMenuProps({}, { suppressRefError: true });
Expand Down
40 changes: 40 additions & 0 deletions packages/react/src/components/MultiSelect/MultiSelect.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import MultiSelect from '.';
import FilterableMultiSelect from './FilterableMultiSelect';
import Button from '../Button';
import ButtonSet from '../ButtonSet';
import { Tabs, Tab, TabList, TabPanels, TabPanel } from '@carbon/react';

export default {
title: 'Components/MultiSelect',
Expand Down Expand Up @@ -273,6 +274,45 @@ export const Filterable = (args) => {
);
};

export const Test = (args) => {
return (
<Tabs>
<TabList aria-label="List of tabs">
<Tab>Overview</Tab>
</TabList>

<TabPanels>
<TabPanel>
<FilterableMultiSelect
style={{ marginTop: '3rem' }}
key={'t1'}
helperText="INTABS"
label="label"
titleText={'Title'}
itemToString={(item) => item}
items={[
'AAAB1',
'AAAB2',
'AAAB3',
'AAAB4',
'AAAB5',
'AAAB6',
'AAAB7',
'AAAB8',
'AAAB9',
'AAABA',
'AAABB',
'AAABC',
'AAABD',
'AAABF',
]}
/>
</TabPanel>
</TabPanels>
</Tabs>
);
};

Filterable.argTypes = {
onChange: {
action: 'onChange',
Expand Down

0 comments on commit 05be270

Please sign in to comment.