Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed EuiSwitch clicking on disabled label #2575

Merged
merged 3 commits into from
Dec 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

**Bug fixes**

- Fixed `EuiSwitch` clicking on disabled label ([#2575](https://github.com/elastic/eui/pull/2575))
- Fixed `EuiDataGrid` schema detection on already defined column schemas ([#2550](https://github.com/elastic/eui/pull/2550))
- Added `euiTextBreakWord()` to `EuiToast` header ([#2549](https://github.com/elastic/eui/pull/2549))
- Fixed `.eui-textBreakAll` on Firefox ([#2549](https://github.com/elastic/eui/pull/2549))
Expand Down
20 changes: 13 additions & 7 deletions src/components/form/switch/switch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React, {
FunctionComponent,
ReactNode,
useState,
useCallback,
} from 'react';
import classNames from 'classnames';

Expand Down Expand Up @@ -49,13 +50,18 @@ export const EuiSwitch: FunctionComponent<EuiSwitchProps> = ({
const [switchId] = useState(id || makeId());
const [labelId] = useState(makeId());

const onClick = (
e: React.MouseEvent<HTMLButtonElement | HTMLParagraphElement>
) => {
const event = (e as unknown) as EuiSwitchEvent;
event.target.checked = !checked;
onChange(event);
};
const onClick = useCallback(
(e: React.MouseEvent<HTMLButtonElement | HTMLParagraphElement>) => {
if (disabled) {
return;
}

const event = (e as unknown) as EuiSwitchEvent;
event.target.checked = !checked;
onChange(event);
},
[checked, disabled, onChange]
);

const classes = classNames(
'euiSwitch',
Expand Down