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 2 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, positioning (regression) ([#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
2 changes: 1 addition & 1 deletion src/components/form/switch/_switch.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.euiSwitch {
position: relative;
display: inline-block;
display: flex;
Copy link
Contributor

@thompsongl thompsongl Dec 2, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should remain as inline-block. The display property here hasn't changed recently, and there doesn't appear to be any regressions with layout.

The .euiSwitch__label display property should be inline to match previous word wrapping.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed there's an issue using the <p> tag when placed inside of an EuiText block and have already started a PR to fix this. I'll fix the wrapping as well in that PR, so we can safely, for now, revert this display change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well. The display change was reverted

min-height: $euiSwitchHeight;

.euiSwitch__label {
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