Skip to content

Selectively hide focus ring via :focus-visible polyfill support - #660

Merged
cdata merged 1 commit into
masterfrom
focus-ring-via-focus-visible
Jun 27, 2019
Merged

cdata merged 1 commit into
masterfrom
focus-ring-via-focus-visible

Conversation

@cdata

@cdata cdata commented Jun 25, 2019

Copy link
Copy Markdown
Contributor

:focus-visible support

This change proposes that we integrate with the :focus-visible polyfill (finally possible now that WICG/focus-visible#196 has landed in a release), and rely on its signaling to selectively disable the default focus ring for non-keyboard interactions.

Additional highlights of this change include:

  • The custom element mixin originally created as an example for Shadow DOM support WICG/focus-visible#196 has been adapted and added in our project
  • Docs have been updated to include information on the polyfill and the use case it supports
  • If the polyfill is not included on the page, the focus ring will behave as it did before this change

Examples

This change, polyfill not present on the page
focusvisible-without-polyfill
This change, with :focus-visible polyfill
focusvisible-with-polyfill

Fixes #463

@cdata
cdata requested a review from elalish June 25, 2019 23:20
@cdata

cdata commented Jun 25, 2019

Copy link
Copy Markdown
Contributor Author

cc @yuinchien @mrdoob just a heads up that our focus rings will be improved soon 🖖

@cdata

cdata commented Jun 25, 2019

Copy link
Copy Markdown
Contributor Author

cc @robdodson

@cdata cdata added this to the v0.6.0 milestone Jun 25, 2019

@elalish elalish left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Surprising how much boiler plate is necessary to include this polyfill.

};

// IE11 doesn't natively support custom elements or JavaScript class
// syntax The mixin implementation assumes that the user will take the

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
// syntax The mixin implementation assumes that the user will take the
// syntax. The mixin implementation assumes that the user will take the

@cdata

cdata commented Jun 27, 2019

Copy link
Copy Markdown
Contributor Author

Surprising how much boiler plate is necessary to include this polyfill.

Are you referring to the docs modifications required?

@cdata
cdata merged commit 6a25e49 into master Jun 27, 2019
@elalish

elalish commented Jun 27, 2019

Copy link
Copy Markdown
Contributor

No, just the new mixin with the coordinator and event listeners and such.

@cdata

cdata commented Jun 27, 2019

Copy link
Copy Markdown
Contributor Author

@elalish it's true, and unfortunate. If you are interested in the gritty details, I recommend reviewing WICG/focus-visible#196

@cdata cdata self-assigned this Aug 26, 2019
@elalish
elalish deleted the focus-ring-via-focus-visible branch February 3, 2020 18:24
elalish pushed a commit to elalish/model-viewer that referenced this pull request Feb 4, 2020
Christopher Joel
 
Opt-in to :focus-visible polyfill when available (google#660)
@Sbstnlhmchr

Sbstnlhmchr commented Mar 25, 2020 •

Copy link
Copy Markdown

hello everyone, unfortunately I don't know my way around - I'm more of a user. On my website I still have the problem with: focus. Can someone help me there?
https://kuckkuck.com/portfolio/case-4/
https://framework.tv/leistungen/digital/webar-beispiel/

@mithru

mithru commented Jul 17, 2020

Copy link
Copy Markdown

just make sure the focus-visible.js is included in your header. You probably started your modelviewer page with an older example that didn't have it included.

pick it up from the repo or this link:
https://unpkg.com/[email protected]/dist/focus-visible.js

@mithru mithru mentioned this pull request Jul 17, 2020
@Sbstnlhmchr

Copy link
Copy Markdown

@mithru THX! works perfectly

@Bihan001

Copy link
Copy Markdown

Adding "data-js-focus-visible" attribute to model-viewer removes the outline without any external dependency.
<model-viewer data-js-focus-visible></model-viewer>

@elalish

elalish commented Jan 28, 2021

Copy link
Copy Markdown
Contributor

@Bihan001 Are you sure? Doesn't it still need the polyfill included? Can you show a Glitch example or something?

@Bihan001

Copy link
Copy Markdown

@Bihan001 Are you sure? Doesn't it still need the polyfill included? Can you show a Glitch example or something?

I'm using react and no polyfill or additional styling was required, simply adding the attribute to model-viewer removed the outline for me.

@elalish

elalish commented Jan 28, 2021

Copy link
Copy Markdown
Contributor

@Bihan001 I'm guessing that means the focus-visible polyfill is included by default in React.

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.

Focus ring via :focus-visible

5 participants