Skip to content

Commit

Permalink
fix(toggleswitch): fix state and replace onkeypress with onkeyup
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Ricardo Lüders committed Sep 23, 2023
1 parent 5496dcb commit aea21c2
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/components/ToggleSwitch/ToggleSwitch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const ToggleSwitch: FC<ToggleSwitchProps> = ({
toggle();
};

const handleKeyPress = (event: KeyboardEvent<HTMLButtonElement>): void => {
const handleOnKeyUp = (event: KeyboardEvent<HTMLButtonElement>): void => {
event.preventDefault();
};

Expand All @@ -67,7 +67,7 @@ export const ToggleSwitch: FC<ToggleSwitchProps> = ({
disabled={disabled}
id={`${id}-flowbite-toggleswitch`}
onClick={handleClick}
onKeyPress={handleKeyPress}
onKeyUp={handleOnKeyUp}
role="switch"
tabIndex={0}
type="button"
Expand All @@ -79,7 +79,7 @@ export const ToggleSwitch: FC<ToggleSwitchProps> = ({
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 ? (
Expand Down

0 comments on commit aea21c2

Please sign in to comment.