Skip to content

Add a polyfill for the focus-visible selector - #5452

Merged
adamconroy merged 2 commits into
masterfrom
bugfix/focus-visible-polyfill
Sep 24, 2019
Merged

adamconroy merged 2 commits into
masterfrom
bugfix/focus-visible-polyfill

Conversation

@adamconroy

Copy link
Copy Markdown
Contributor

Implement the https://github.com/WICG/focus-visible polyfill as per the https://www.w3.org/TR/UNDERSTANDING-WCAG20/navigation-mechanisms-focus-visible.html proposal to explicitly show keyboard focus separately from mouse focus.

The proposed colors are entirely placeholder but they work in our current light and dark styles. There are some anomalies where we have explicitly set focus in our themes that will need to be removed/changed (input["checkbox"]:focus) but focus barely works in the program right now anyway.

0w3F4D9
lNxIqWx
KQXd7rF

@@ -0,0 +1,2 @@
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t():"function"==typeof define&&define.amd?define(t):t()}(0,function(){"use strict";function e(e){var t=!0,n=!1,o=null,d={text:!0,search:!0,url:!0,tel:!0,email:!0,password:!0,number:!0,date:!0,month:!0,week:!0,time:!0,datetime:!0,"datetime-local":!0};function i(e){return!!(e&&e!==document&&"HTML"!==e.nodeName&&"BODY"!==e.nodeName&&"classList"in e&&"contains"in e.classList)}function s(e){e.classList.contains("focus-visible")||(e.classList.add("focus-visible"),e.setAttribute("data-focus-visible-added",""))}function u(e){t=!1}function a(){document.addEventListener("mousemove",c),document.addEventListener("mousedown",c),document.addEventListener("mouseup",c),document.addEventListener("pointermove",c),document.addEventListener("pointerdown",c),document.addEventListener("pointerup",c),document.addEventListener("touchmove",c),document.addEventListener("touchstart",c),document.addEventListener("touchend",c)}function c(e){e.target.nodeName&&"html"===e.target.nodeName.toLowerCase()||(t=!1,document.removeEventListener("mousemove",c),document.removeEventListener("mousedown",c),document.removeEventListener("mouseup",c),document.removeEventListener("pointermove",c),document.removeEventListener("pointerdown",c),document.removeEventListener("pointerup",c),document.removeEventListener("touchmove",c),document.removeEventListener("touchstart",c),document.removeEventListener("touchend",c))}document.addEventListener("keydown",function(n){n.metaKey||n.altKey||n.ctrlKey||(i(e.activeElement)&&s(e.activeElement),t=!0)},!0),document.addEventListener("mousedown",u,!0),document.addEventListener("pointerdown",u,!0),document.addEventListener("touchstart",u,!0),document.addEventListener("visibilitychange",function(e){"hidden"==document.visibilityState&&(n&&(t=!0),a())},!0),a(),e.addEventListener("focus",function(e){var n,o,u;i(e.target)&&(t||(n=e.target,o=n.type,"INPUT"==(u=n.tagName)&&d[o]&&!n.readOnly||"TEXTAREA"==u&&!n.readOnly||n.isContentEditable))&&s(e.target)},!0),e.addEventListener("blur",function(e){var t;i(e.target)&&(e.target.classList.contains("focus-visible")||e.target.hasAttribute("data-focus-visible-added"))&&(n=!0,window.clearTimeout(o),o=window.setTimeout(function(){n=!1,window.clearTimeout(o)},100),(t=e.target).hasAttribute("data-focus-visible-added")&&(t.classList.remove("focus-visible"),t.removeAttribute("data-focus-visible-added")))},!0),e.nodeType===Node.DOCUMENT_FRAGMENT_NODE&&e.host?e.host.setAttribute("data-js-focus-visible",""):e.nodeType===Node.DOCUMENT_NODE&&document.documentElement.classList.add("js-focus-visible")}if("undefined"!=typeof window&&"undefined"!=typeof document){var t;window.applyFocusVisiblePolyfill=e;try{t=new CustomEvent("focus-visible-polyfill-ready")}catch(e){(t=document.createEvent("CustomEvent")).initCustomEvent("focus-visible-polyfill-ready",!1,!1,{})}window.dispatchEvent(t)}"undefined"!=typeof document&&e(document)});
//# sourceMappingURL=focus-visible.min.js.map

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should we also commit the .map file and the original .js file for debugging? (if not, should we remove the source mapping?)

@jmcphers

Copy link
Copy Markdown
Member

While this is going to be a big boon to keyboard-only users, I think most mouse users will find these colors and indicators too jarring. What do you and/or @gtritchie think of guarding the behavior with a preference?

@gtritchie gtritchie left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

(shortening my prior blurt): The purpose of the polyfill is to support :focus-visible pseudo class, which shows focus visibly if it using keyboard, but not if using mouse. If that is working well, then a preference doesn't seem necessary.

Comment thread src/gwt/gwt.iml Outdated
<component name="FacetManager">
<facet type="gwt" name="GWT">
<configuration>
<setting name="gwtSdkUrl" value="file://$MODULE_DIR$/lib/gwt/2.8.1" />

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This file is annoying (it's an IntelliJ metadata file), not sure we should even have it checked in. Given we currently do, it shouldn't be referencing gwt 2.8.1 (or 2.8.2, since we now use a custom version, aka gwt-rstudio-1.3.

I recently tweaked this file in my configuration to get rid of the FacetManager section altogether, see ba1591c#diff-0c742bc7155736d62bc3454aeb47871d

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm on the fence. Annoying that we use a custom version so it's kind of weird. If we're not going to keep it totally accurate maybe we should just remove it from the repo altogether?

@gtritchie gtritchie left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM!

@adamconroy
adamconroy merged commit 8342d4a into master Sep 24, 2019
@valerie-rstudio
valerie-rstudio deleted the bugfix/focus-visible-polyfill branch January 21, 2022 17:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants