mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Fix <Switch/> checked callback attribute value (#5360)
This commit is contained in:
parent
d99cc5a015
commit
cc9ee67dc2
@ -48,4 +48,24 @@ describe("<Switch/>", () => {
|
||||
|
||||
expect(onClick).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("returns true checked attribute in a onChange callback", () => {
|
||||
const onClick = jest.fn();
|
||||
const { getByTestId } = render(<Switch onChange={onClick} checked={true}/>);
|
||||
const switcher = getByTestId("switch");
|
||||
|
||||
fireEvent.click(switcher);
|
||||
|
||||
expect(onClick).toHaveBeenCalledWith(false, expect.any(Object));
|
||||
});
|
||||
|
||||
it("returns false checked attribute in a onChange callback", () => {
|
||||
const onClick = jest.fn();
|
||||
const { getByTestId } = render(<Switch onChange={onClick}/>);
|
||||
const switcher = getByTestId("switch");
|
||||
|
||||
fireEvent.click(switcher);
|
||||
|
||||
expect(onClick).toHaveBeenCalledWith(true, expect.any(Object));
|
||||
});
|
||||
});
|
||||
|
||||
@ -17,7 +17,13 @@ export function Switch({ children, disabled, onChange, ...props }: SwitchProps)
|
||||
return (
|
||||
<label className={cssNames(styles.Switch, { [styles.disabled]: disabled })} data-testid="switch">
|
||||
{children}
|
||||
<input type="checkbox" role="switch" disabled={disabled} onChange={(event) => onChange?.(props.checked, event)} {...props}/>
|
||||
<input
|
||||
type="checkbox"
|
||||
role="switch"
|
||||
disabled={disabled}
|
||||
onChange={(event) => onChange?.(event.target.checked, event)}
|
||||
{...props}
|
||||
/>
|
||||
</label>
|
||||
);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user