Skip to content

Commit b05b1c2

Browse files
author
darianstlex
committed
IE multi select click fix
1 parent b515381 commit b05b1c2

4 files changed

Lines changed: 11 additions & 26 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-sm-select",
3-
"version": "1.0.8",
3+
"version": "1.0.9",
44
"description": "React Multi/Single Select Component",
55
"main": "./dist/index.js",
66
"module": "./es/index.js",

src/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ export class MultiSelect extends React.Component {
7979
selectAll: false,
8080
focusIndex: p.enableSearch ? -1 : -2,
8181
searchText: '',
82+
mouseHover: false,
8283
};
8384

8485
this.multiSelectRef = React.createRef();
@@ -135,10 +136,10 @@ export class MultiSelect extends React.Component {
135136
/**
136137
* Handle click on document, to detect click outside
137138
*/
138-
handleDocumentClick = event => {
139+
handleDocumentClick = () => {
139140
if (this.props.disabled) return;
140141

141-
if (!u.eventPath(event).includes(this.multiSelectRef.current)) {
142+
if (!this.state.mouseHover) {
142143
this.setState({ expanded: false, hasFocus: false });
143144
u.removeDocumentClickListener(this.handleDocumentClick);
144145
this.onEvent('onBlur');
@@ -191,6 +192,7 @@ export class MultiSelect extends React.Component {
191192
* @param expanded Boolean
192193
*/
193194
handleHover = expanded => {
195+
this.setState({ mouseHover: expanded });
194196
if (this.props.shouldToggleOnHover) this.toggleDropDown(null, expanded);
195197
};
196198

src/index.test.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,16 +186,17 @@ describe('MultiSelect', () => {
186186

187187
describe('handleDocumentClick', () => {
188188
it('should remove document click listener, set state and call onBlur', () => {
189-
wrapper.instance().handleDocumentClick({ path: ['test'] });
189+
wrapper.setState({ mouseHover: false });
190+
wrapper.instance().handleDocumentClick();
190191

191192
expect(setState).toHaveBeenCalledWith({ expanded: false, hasFocus: false });
192193
expect(utils.removeDocumentClickListener).toHaveBeenCalledWith(wrapper.instance().handleDocumentClick);
193194
expect(onEvent).toHaveBeenCalledWith('onBlur');
194195
});
195196

196197
it('should not remove document click listener, set state and call onBlur if click is internal', () => {
197-
wrapper.instance().multiSelectRef.current = 'test';
198-
wrapper.instance().handleDocumentClick({ path: ['test'] });
198+
wrapper.setState({ mouseHover: true });
199+
wrapper.instance().handleDocumentClick();
199200

200201
expect(setState).not.toHaveBeenCalled();
201202
expect(utils.removeDocumentClickListener).not.toHaveBeenCalled();
@@ -204,7 +205,8 @@ describe('MultiSelect', () => {
204205

205206
it('should not remove document click listener, set state and call onBlur if disabled', () => {
206207
const wrapper = shallow(<MultiSelect {...props} disabled={true} />);
207-
wrapper.instance().handleDocumentClick({ path: ['test'] });
208+
wrapper.setState({ mouseHover: true });
209+
wrapper.instance().handleDocumentClick();
208210

209211
expect(setState).not.toHaveBeenCalled();
210212
expect(utils.removeDocumentClickListener).not.toHaveBeenCalled();

src/utils.js

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -81,22 +81,3 @@ export const stopPreventPropagation = event => {
8181
event.stopPropagation();
8282
event.preventDefault();
8383
};
84-
85-
/**
86-
* Calculate element path for browser compatibility
87-
* @param event.composedPath
88-
* @param event.path return
89-
* @param event.target
90-
* @returns {*}
91-
*/
92-
export const eventPath = event => {
93-
const inPath = (event.composedPath && event.composedPath()) || event.path;
94-
const target = event.target;
95-
96-
if (inPath != null) return (inPath.indexOf(window) < 0) ? inPath.concat(window) : inPath; // safari
97-
if (target === window) return [window];
98-
99-
const getParents = ({parentNode}, memo = []) => parentNode ? getParents(parentNode, memo.concat(parentNode)) : memo;
100-
101-
return [target].concat(getParents(target), window);
102-
};

0 commit comments

Comments
 (0)