Skip to content

Commit

Permalink
EuiSelect: prevent propagation on inconsistent mouseup events (#1926)
Browse files Browse the repository at this point in the history
* prevent propagation on inconsitent mouseup events

* documentation

* #1926 CL entry
  • Loading branch information
thompsongl authored May 8, 2019
1 parent 3988503 commit debab6b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
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

0 comments on commit debab6b

Please sign in to comment.