Skip to content

Commit

Permalink
fix(structuredlistinput): call onchange (#13625)
Browse files Browse the repository at this point in the history
Co-authored-by: Andrea N. Cardona <cardona.n.andrea@gmail.com>
  • Loading branch information
tay1orjones and andreancardona authored Apr 19, 2023
1 parent b20f4f2 commit f68f0fc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const customCellClass = 'structured-list-cell-custom-class';
const inputNameValue = 'list-radio-input';
const onKeyDownHandlerFn = jest.fn();
const onKeyDownBodyHandlerFn = jest.fn();
const onChangeHandlerFn = jest.fn();

const user = userEvent.setup();

Expand Down Expand Up @@ -87,6 +88,7 @@ const structuredListBodyRowGenerator = (numRows, rest) => {
title={`row-${i}`}
name={inputNameValue}
className={customInputClass}
onChange={onChangeHandlerFn}
/>
<StructuredListCell>
<CheckmarkFilled
Expand Down Expand Up @@ -321,6 +323,12 @@ describe('StructuredList', () => {
expect(input).toHaveAttribute('aria-label', testAriaLabel);
});
});
it('should call onChange on change', async () => {
renderSelectionVariant();
const inputElement = screen.getByTitle('row-0');
await userEvent.click(inputElement);
expect(onChangeHandlerFn).toHaveBeenCalled();
});
});

describe('StructuredListCell', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ export function StructuredListInput(props) {
name = `structured-list-input-${defaultId}`,
title,
id,
onChange,
...other
} = props;
const prefix = usePrefix();
Expand All @@ -260,6 +261,7 @@ export function StructuredListInput(props) {
value={row?.id ?? ''}
onChange={(event) => {
setSelectedRow(event.target.value);
onChange(event);
}}
id={id ?? defaultId}
className={classes}
Expand Down

0 comments on commit f68f0fc

Please sign in to comment.