Fix Toggle options stability
This commit is contained in:
parent
d522090872
commit
3def20bf0d
@ -26,19 +26,14 @@ export function Toggle(props: ToggleProps): JSX.Element {
|
|||||||
"onClick",
|
"onClick",
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const options: Parameters<typeof createControllableSignal<boolean>>[0] = {
|
const [isPressed, setPressed] = createControllableSignal<boolean>({
|
||||||
value: () => local.pressed,
|
value: () => local.pressed,
|
||||||
defaultValue: () => local.defaultPressed ?? false,
|
defaultValue: () => local.defaultPressed ?? false,
|
||||||
};
|
onChange: local.onPressedChange,
|
||||||
|
});
|
||||||
if (local.onPressedChange) {
|
|
||||||
options.onChange = local.onPressedChange;
|
|
||||||
}
|
|
||||||
|
|
||||||
const [isPressed, setPressed] = createControllableSignal<boolean>(options);
|
|
||||||
|
|
||||||
const handleClick: JSX.EventHandler<HTMLButtonElement, MouseEvent> = (e) => {
|
const handleClick: JSX.EventHandler<HTMLButtonElement, MouseEvent> = (e) => {
|
||||||
if (typeof local.onClick === "function") local.onClick(e);
|
local.onClick?.(e);
|
||||||
if (!local.disabled) setPressed(!isPressed());
|
if (!local.disabled) setPressed(!isPressed());
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user