Fix ToggleGroup disabled handling
This commit is contained in:
parent
40e57715f9
commit
315f5e4ae2
@ -24,8 +24,10 @@ export function ToggleGroupItem(props: ToggleGroupItemProps): JSX.Element {
|
||||
disabled={isDisabled()}
|
||||
{...rest}
|
||||
onClick={(e) => {
|
||||
if (typeof rest.onClick === "function") rest.onClick(e);
|
||||
if (!isDisabled()) ctx.onItemPress(local.value);
|
||||
if (!isDisabled()) {
|
||||
if (typeof rest.onClick === "function") rest.onClick(e);
|
||||
ctx.onItemPress(local.value);
|
||||
}
|
||||
}}
|
||||
>
|
||||
{local.children}
|
||||
|
||||
@ -71,4 +71,14 @@ describe("ToggleGroup multiple", () => {
|
||||
fireEvent.click(screen.getByRole("button"));
|
||||
expect(screen.getByRole("button").getAttribute("aria-pressed")).toBe("false");
|
||||
});
|
||||
|
||||
it("disabled item is not pressable", () => {
|
||||
render(() => (
|
||||
<ToggleGroup type="single">
|
||||
<ToggleGroup.Item value="a" disabled>A</ToggleGroup.Item>
|
||||
</ToggleGroup>
|
||||
));
|
||||
fireEvent.click(screen.getByRole("button"));
|
||||
expect(screen.getByRole("button").getAttribute("aria-pressed")).toBe("false");
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user