Skip to content

Commit

Permalink
fix(ComboBox): open menu on selected clear(carbon-design-system#11397)
Browse files Browse the repository at this point in the history
  • Loading branch information
pmweeks98 committed Jun 3, 2022
1 parent 864e94a commit 482f26a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
19 changes: 18 additions & 1 deletion packages/react/src/components/ComboBox/ComboBox-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import React from 'react';
import { mount } from 'enzyme';
import { render, screen, within } from '@testing-library/react';
import { render, screen, within, fireEvent } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import {
findListBoxNode,
Expand Down Expand Up @@ -110,6 +110,23 @@ describe('ComboBox', () => {
});
});

it('should clear the selectedItem when clicking on the clear option', () => {
render(<ComboBox {...mockProps} selectedItem={mockProps.items[0]} />);
expect(screen.getByRole('combobox').value).toEqual(
mockProps.items[0].label
);

fireEvent.click(screen.getByTitle('Clear selected item'));
expect(screen.getByRole('combobox').value).toEqual('');
});

it('should show listbox on selected item clear', () => {
render(<ComboBox {...mockProps} selectedItem={mockProps.items[0]} />);

fireEvent.click(screen.getByTitle('Clear selected item'));
expect(screen.getAllByRole('option').length).toBe(mockProps.items.length);
});

describe('should display initially selected item found in `initialSelectedItem`', () => {
it('using an object type for the `initialSelectedItem` prop', () => {
const wrapper = mount(
Expand Down
5 changes: 4 additions & 1 deletion packages/react/src/components/ComboBox/ComboBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,10 @@ const ComboBox = React.forwardRef((props, ref) => {
clearSelection={clearSelection}
translateWithId={translateWithId}
disabled={disabled}
onClearSelection={handleSelectionClear}
onClearSelection={() => {
toggleMenu();
handleSelectionClear();
}}
/>
)}
<ListBoxTrigger
Expand Down

0 comments on commit 482f26a

Please sign in to comment.