-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FIX #14628] Don’t use preventDefault() on IE unless the user pressed…
… enter (#14667) * Don’t use prevent default on IE unless the user pressed enter * Implament ie fix on number fields too * share the ie detection lib * change file names and export types
- Loading branch information
1 parent
e765e3b
commit cd9437b
Showing
3 changed files
with
35 additions
and
4 deletions.
There are no files selected for viewing
6 changes: 4 additions & 2 deletions
6
src/core_plugins/metrics/public/components/lib/create_number_handler.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
import _ from 'lodash'; | ||
import { detectIE } from './detect_ie'; | ||
export default (handleChange) => { | ||
return (name, defaultValue) => (e) => { | ||
e.preventDefault(); | ||
if (!detectIE() || e.keyCode === 13) e.preventDefault(); | ||
|
||
const value = Number(_.get(e, 'target.value', defaultValue)); | ||
if (_.isFunction(handleChange)) { | ||
return handleChange({ [name]: value }); | ||
} | ||
}; | ||
}; | ||
}; |
8 changes: 6 additions & 2 deletions
8
src/core_plugins/metrics/public/components/lib/create_text_handler.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,14 @@ | ||
import _ from 'lodash'; | ||
import { detectIE } from './detect_ie'; | ||
|
||
export default (handleChange) => { | ||
return (name, defaultValue) => (e) => { | ||
e.preventDefault(); | ||
// IE preventDefault breaks input, but we still need top prevent enter from being pressed | ||
if (!detectIE() || e.keyCode === 13) e.preventDefault(); | ||
|
||
const value = _.get(e, 'target.value', defaultValue); | ||
if (_.isFunction(handleChange)) { | ||
return handleChange({ [name]: value }); | ||
} | ||
}; | ||
}; | ||
}; |
25 changes: 25 additions & 0 deletions
25
src/core_plugins/metrics/public/components/lib/detect_ie.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
export function detectIE() { | ||
const ua = window.navigator.userAgent; | ||
|
||
const msie = ua.indexOf('MSIE '); | ||
if (msie > 0) { | ||
// IE 10 or older => return version number | ||
return parseInt(ua.substring(msie + 5, ua.indexOf('.', msie)), 10); | ||
} | ||
|
||
const trident = ua.indexOf('Trident/'); | ||
if (trident > 0) { | ||
// IE 11 => return version number | ||
const rv = ua.indexOf('rv:'); | ||
return parseInt(ua.substring(rv + 3, ua.indexOf('.', rv)), 10); | ||
} | ||
|
||
const edge = ua.indexOf('Edge/'); | ||
if (edge > 0) { | ||
// Edge (IE 12+) => return version number | ||
return parseInt(ua.substring(edge + 5, ua.indexOf('.', edge)), 10); | ||
} | ||
|
||
// other browser | ||
return false; | ||
} |