Skip to content

postcss-focus-within : browser compat #520

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion plugins/postcss-focus-within/src/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ export default function focusWithin(opts) {
const handleFocusChange = generateHandler(options.replaceWith);

const initialize = function initializeEventListeners() {
document.documentElement.classList.add('js-focus-within');
if (document.documentElement.className.indexOf('js-focus-within') > -1) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the class was already added this function was likely already called.

return;
}

document.documentElement.className = document.documentElement.className + ' js-focus-within';
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Low effort fallback for classList which does not exist in IE9

document.addEventListener('focus', handleFocusChange, true);
document.addEventListener('blur', handleFocusChange, true);
};
Expand Down
1 change: 1 addition & 0 deletions plugins/postcss-focus-within/test/_browser.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<link rel="stylesheet" href="/test/browser.expect.css">
<script src="/dist/browser-global.js"></script>
<script>self._focusWithinInit = focusWithinInit</script>
<script>self._focusWithinInit()</script>
</head>
<body>
<div id="a-grand-parent">
Expand Down