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

EuiSelect: prevent propagation on inconsistent mouseup events #1926

Merged
merged 7 commits into from
May 8, 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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
## [`master`](https://github.com/elastic/eui/tree/master)

**Bug fixes**

- Removed unused prop enum of `l` in `EuiButton` ([#1936](https://github.com/elastic/eui/pull/1936))
- Fixed `EuiSelect` browser event inconsistencies by normalizing `mouseup` propagation ([#1926](https://github.com/elastic/eui/pull/1926))

## [`11.0.1`](https://github.com/elastic/eui/tree/v11.0.1)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
} from '../../components';

import {
EuiCallOut,
EuiCode,
EuiOutsideClickDetector,
} from '../../../../src/components';
Expand All @@ -26,10 +27,21 @@ export const OutsideClickDetectorExample = {
code: outsideClickDetectorHtml,
}],
text: (
<p>
Use <EuiCode>EuiOutsideClickDetector</EuiCode> to trigger a handler when the user clicks outside of the
child element.
</p>
<React.Fragment>
<p>
Use <EuiCode>EuiOutsideClickDetector</EuiCode> to trigger a handler when the user clicks outside of the
child element.
</p>
<EuiCallOut
title="Use with EuiSelect"
color="warning"
>
<p>
<EuiCode>EuiSelect</EuiCode> normalizes browser event inconsistencies with <EuiCode>select</EuiCode> elements
and as a result may not trigger <EuiCode>EuiOutsideClickDetector</EuiCode> when targeted with mouse events.
</p>
</EuiCallOut>
</React.Fragment>
),
props: { EuiOutsideClickDetector },
demo: <OutsideClickDetector />,
Expand Down
12 changes: 12 additions & 0 deletions src/components/form/select/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,19 @@ export const EuiSelect = ({
value,
prepend,
append,
onMouseUp,
...rest
}) => {

const handleMouseUp = e => {
// Normalizes cross-browser mouse eventing by preventing propagation,
// notably for use in conjunction with EuiOutsideClickDetector.
// See https://github.com/elastic/eui/pull/1926 for full discussion on
// rationale and alternatives should this intervention become problematic.
e.nativeEvent.stopImmediatePropagation();
if (onMouseUp) onMouseUp(e);
};

const classes = classNames(
'euiSelect',
{
Expand Down Expand Up @@ -74,6 +85,7 @@ export const EuiSelect = ({
ref={inputRef}
defaultValue={selectDefaultValue}
value={value}
onMouseUp={handleMouseUp}
{...rest}
>
{emptyOptionNode}
Expand Down