diff --git a/components/lib/chips/Chips.js b/components/lib/chips/Chips.js index ad98db5476..863a1c6aea 100644 --- a/components/lib/chips/Chips.js +++ b/components/lib/chips/Chips.js @@ -106,9 +106,7 @@ export const Chips = React.memo( event.preventDefault(); } else if (props.separator === ',') { // GitHub #3885 Android Opera gives strange code 229 for comma - const ANDROID_COMMA = 229; - - if (event.key === props.separator || event.which === ANDROID_COMMA) { + if (event.key === props.separator || (DomHandler.isAndroid() && event.which === 229)) { addItem(event, inputValue, true); } } diff --git a/components/lib/inputmask/InputMask.js b/components/lib/inputmask/InputMask.js index f10dd1dffe..215f9c3139 100644 --- a/components/lib/inputmask/InputMask.js +++ b/components/lib/inputmask/InputMask.js @@ -190,12 +190,11 @@ export const InputMask = React.memo( pos, begin, end; - let iPhone = /iphone/i.test(DomHandler.getUserAgent()); oldVal.current = elementRef.current.value; //backspace, delete, and escape get special treatment - if (k === 8 || k === 46 || (iPhone && k === 127)) { + if (k === 8 || k === 46 || (DomHandler.isIOS() && k === 127)) { pos = caret(); begin = pos.begin; end = pos.end; @@ -256,7 +255,7 @@ export const InputMask = React.memo( writeBuffer(); next = seekNext(p); - if (/android/i.test(DomHandler.getUserAgent())) { + if (DomHandler.isAndroid()) { //Path for CSP Violation on FireFox OS 1.1 let proxy = () => { caret(next); @@ -494,9 +493,7 @@ export const InputMask = React.memo( '*': '[A-Za-z0-9]' }; - let ua = DomHandler.getUserAgent(); - - androidChrome.current = /chrome/i.test(ua) && /android/i.test(ua); + androidChrome.current = DomHandler.isChrome() && DomHandler.isAndroid(); let maskTokens = props.mask.split(''); diff --git a/components/lib/utils/DomHandler.js b/components/lib/utils/DomHandler.js index a25ee800bb..8bab44ffb8 100644 --- a/components/lib/utils/DomHandler.js +++ b/components/lib/utils/DomHandler.js @@ -647,6 +647,10 @@ export default class DomHandler { return /(android)/i.test(navigator.userAgent); } + static isChrome() { + return /(chrome)/i.test(navigator.userAgent); + } + static isTouchDevice() { return 'ontouchstart' in window || navigator.maxTouchPoints > 0 || navigator.msMaxTouchPoints > 0; } diff --git a/components/lib/utils/Mask.js b/components/lib/utils/Mask.js index d80af9a79d..aaf0903d09 100644 --- a/components/lib/utils/Mask.js +++ b/components/lib/utils/Mask.js @@ -177,12 +177,11 @@ export function mask(el, options) { pos, begin, end; - let iPhone = /iphone/i.test(DomHandler.getUserAgent()); oldVal = el.value; //backspace, delete, and escape get special treatment - if (k === 8 || k === 46 || (iPhone && k === 127)) { + if (k === 8 || k === 46 || (DomHandler.isIOS() && k === 127)) { pos = caret(); begin = pos.begin; end = pos.end; @@ -243,7 +242,7 @@ export function mask(el, options) { writeBuffer(); next = seekNext(p); - if (/android/i.test(DomHandler.getUserAgent())) { + if (DomHandler.isAndroid()) { //Path for CSP Violation on FireFox OS 1.1 let proxy = () => { caret(next); @@ -453,9 +452,7 @@ export function mask(el, options) { '*': '[A-Za-z0-9]' }; - let ua = DomHandler.getUserAgent(); - - androidChrome = /chrome/i.test(ua) && /android/i.test(ua); + androidChrome = DomHandler.isChrome() && DomHandler.isAndroid(); let maskTokens = options.mask.split('');