Skip to content

Commit

Permalink
fix(ComboBox): fix fully controlled story and delete test story (#18680)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamalston authored Feb 25, 2025
1 parent faf6498 commit d4a071a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 29 deletions.
4 changes: 2 additions & 2 deletions packages/react/src/components/ComboBox/ComboBox-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ describe('ComboBox', () => {
expect(findInputNode()).toHaveDisplayValue(mockProps.items[1]);
});

it('should not revert to initialSelectedItem after clearing selection in uncontrolled mode', async () => {
it('should not revert to `initialSelectedItem` after clearing selection in uncontrolled mode', async () => {
// Render a non-fully controlled `ComboBox` using `initialSelectedItem`.
render(
<ComboBox {...mockProps} initialSelectedItem={mockProps.items[0]} />
Expand All @@ -348,7 +348,7 @@ describe('ComboBox', () => {
expect(findInputNode()).toHaveDisplayValue('');
});

it('should ignore updates to initialSelectedItem after initial render in uncontrolled mode', async () => {
it('should ignore updates to `initialSelectedItem` after initial render in uncontrolled mode', async () => {
// Render a non-fully controlled `ComboBox` using `initialSelectedItem`.
const { rerender } = render(
<ComboBox {...mockProps} initialSelectedItem={mockProps.items[0]} />
Expand Down
28 changes: 1 addition & 27 deletions packages/react/src/components/ComboBox/ComboBox.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -384,14 +384,14 @@ export const _fullyControlled = (args) => {
return (
<div>
<ComboBox
{...args}
onChange={onChange}
id="carbon-combobox"
items={options}
selectedItem={value}
itemToString={(item) => (item ? item.text : '')}
titleText="Fully Controlled ComboBox title"
helperText="Combobox helper text"
{...args}
/>
<div
style={{
Expand All @@ -410,32 +410,6 @@ export const _fullyControlled = (args) => {

_fullyControlled.argTypes = { ...sharedArgTypes };

export const _fullyControlled2 = () => {
const [selectedItem, setSelectedItem] = useState(null);

return (
<div
style={{
display: 'flex',
flexDirection: 'column',
gap: '1rem',
width: '256px',
}}>
<ComboBox
id="carbon-combobox"
items={['1', '2', '3']}
onChange={({ selectedItem }) => setSelectedItem(selectedItem)}
selectedItem={selectedItem}
titleText="Fully Controlled ComboBox title"
/>
<Button kind="danger" onClick={() => setSelectedItem(null)} size="md">
Reset
</Button>
<p>Selected value: {`${selectedItem}`}</p>
</div>
);
};

AutocompleteWithTypeahead.argTypes = {
onChange: { action: 'onChange' },
};

0 comments on commit d4a071a

Please sign in to comment.