From aea21c21e283824545073d1df519cee4364bdd52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20L=C3=BCders?= Date: Sat, 23 Sep 2023 10:15:31 +0200 Subject: [PATCH] fix(toggleswitch): fix state and replace onkeypress with onkeyup This commit fixes the state for disable + enabled ToggleSwitch and also replaces the deprecated onKeyPress with onKeyUp BREAKING CHANGE: onKeyPress is deprecated. Please, use onKeyUp instead. fix #986 --- src/components/ToggleSwitch/ToggleSwitch.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/ToggleSwitch/ToggleSwitch.tsx b/src/components/ToggleSwitch/ToggleSwitch.tsx index 85c8338c18..a0ef41e8c2 100644 --- a/src/components/ToggleSwitch/ToggleSwitch.tsx +++ b/src/components/ToggleSwitch/ToggleSwitch.tsx @@ -52,7 +52,7 @@ export const ToggleSwitch: FC = ({ toggle(); }; - const handleKeyPress = (event: KeyboardEvent): void => { + const handleOnKeyUp = (event: KeyboardEvent): void => { event.preventDefault(); }; @@ -67,7 +67,7 @@ export const ToggleSwitch: FC = ({ disabled={disabled} id={`${id}-flowbite-toggleswitch`} onClick={handleClick} - onKeyPress={handleKeyPress} + onKeyUp={handleOnKeyUp} role="switch" tabIndex={0} type="button" @@ -79,7 +79,7 @@ export const ToggleSwitch: FC = ({ className={twMerge( theme.toggle.base, theme.toggle.checked[checked ? 'on' : 'off'], - !disabled && checked && theme.toggle.checked.color[color], + checked && theme.toggle.checked.color[color], )} /> {label?.length ? (