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(ComboBox): fix fully controlled story and delete test story #18680

Merged
merged 1 commit into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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' },
};
Loading