Skip to content

Commit

Permalink
Merge pull request #19890 from tienifr/fix/19848-autofill-input
Browse files Browse the repository at this point in the history
fix: autofill is not a valid selector
  • Loading branch information
robertjchen authored Jun 8, 2023
2 parents 37141ca + a95884e commit 6e7f460
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/libs/isInputAutoFilled.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import isSelectorSupported from './isSelectorSupported';

/**
* Check the input is auto filled or not
* @param {Object} input
* @return {Boolean}
*/
export default function isInputAutoFilled(input) {
if (!input.matches) return false;
return input.matches(':-webkit-autofill') || input.matches(':autofill');
if (isSelectorSupported(':autofill')) {
return input.matches(':-webkit-autofill') || input.matches(':autofill');
}
return input.matches(':-webkit-autofill');
}
13 changes: 13 additions & 0 deletions src/libs/isSelectorSupported/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* Check platform supports the selector or not
* @param {String} selector
* @return {Boolean}
*/
export default function isSelectorSupported(selector) {
try {
document.querySelector(selector);
return true;
} catch (error) {
return false;
}
}
4 changes: 4 additions & 0 deletions src/libs/isSelectorSupported/index.native.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Native platforms do not support the selector
export default function isSelectorSupported() {
return false;
}

0 comments on commit 6e7f460

Please sign in to comment.