Skip to content
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

Fix: add support for :focus-visible selector #5483

Merged
merged 20 commits into from
Oct 25, 2018

Conversation

gjanblaszczyk
Copy link
Member

Description

A proposed fix for #5474
It based on :focus-visible selector.
For now, it works only on Chrome. You have to enable "Experimental Web Platform features" under the Chrome settings (chrome://flags/) to be an able test this solution.
The PR doesn't break other browsers.

Requirements Checklist

  • Feature implemented / Bug fixed
  • If necessary, more likely in a feature request than a bug fix
    • Change has been verified in an actual browser (Chome, Firefox, IE)
    • Unit Tests updated or fixed
    • Docs/guides updated
    • Example created (starter template on JSBin)
  • Reviewed by Two Core Contributors

Sorry, something went wrong.

gjanblaszczyk and others added 5 commits September 3, 2018 11:07

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
sync with origin branch
@gjanblaszczyk gjanblaszczyk changed the title Prevent focus on click v2 Fix: add support for :focus-visible selector Oct 5, 2018
@OwenEdwards
Copy link
Member

"The PR doesn't break other browsers" - is that true? Doesn't this PR disable focus outlines if :focus-visible is not present, so it will disable the outline for all browsers except Chrome with "Experimental Web Platform features" under the Chrome settings (chrome://flags/)" enabled?

We can't do that and break accessibility across all browsers except Chrome with an Experimental flag enabled. I thought this PR was going to integrate the ":focus-visible" polyfill.

@gjanblaszczyk
Copy link
Member Author

gjanblaszczyk commented Oct 8, 2018

Hi Owen, Thanks for the comment.
For your question: "The PR doesn't break other browsers" - is that true?
Yes, it shouldn't break any browsers at least according to some comments from focus-visible polyfill project.
See here:
https://github.com/WICG/focus-visible/blame/master/README.md#L134
I used the same CSS rule:
/* Remove default focus styles for mouse users ONLY if :focus-visible is supported on this platform. */ button:focus:not(:focus-visible) { … }
I think also @gkatsev suggesting using:
:focus:not(:focus-visible) { outline: none; }
#5474 (comment)

I created also codepen demo example here:
https://codepen.io/grbla/pen/PybOYX

@asd29696
Copy link

asd29696 commented Oct 8, 2018 via email

@gkatsev
Copy link
Member

gkatsev commented Oct 9, 2018

What about a general one in the main scss file instead for each component?

.video-js *:focus:not(:focus-visible) {
  outline: none;
}

@OwenEdwards older browsers that don't support that pseudo-selector will ignore the entire block.

@OwenEdwards
Copy link
Member

@gjanblaszczyk and @gkatsev: "older browsers that don't support that pseudo-selector will ignore the entire block." - ahh, thanks for that clarification, I misunderstood that.

Then I agree with @gkatsev's suggestion above, making it generic for all of video.js. Additionally, I'd suggest that we add the :focus-visible polyfill into one of the HTML examples in docs or sandbox, and refer to it in some of the documentation - that will help steer people in that direction if they're concerned about this, rather than them submitting just a univeral outline: none; PR again (like #5027).

@gjanblaszczyk
Copy link
Member Author

Thanks for comments,
@gkatsev I added focus-visible selector to the main file.
Do we want to add focus-visible polyfill to the sandbox demo? If Yes I suggest adding the new focus-visible.html demo to the sandbox directory. any objections?

@gkatsev
Copy link
Member

gkatsev commented Oct 10, 2018

Adding a focus-visible.html.example to the sandbox sounds reasonable to me.

@gkatsev
Copy link
Member

gkatsev commented Oct 22, 2018

You can go to this URL directly chrome://flags/#enable-experimental-web-platform-features

@gkatsev
Copy link
Member

gkatsev commented Oct 22, 2018

@gjanblaszczyk hey, did you get a chance to add the example page using the polyfill?

@gjanblaszczyk
Copy link
Member Author

Hi @gkatsev, not yet but I am planning to do that tomorrow.

Copy link
Member

@gkatsev gkatsev left a comment

Choose a reason for hiding this comment

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

Thanks for the update

This will hide the focus indicator if the element receives focus via the mouse,
but it will still show up on keyboard focus.
*/
.js-focus-visible :focus:not(.focus-visible) {
Copy link
Member

Choose a reason for hiding this comment

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

is this piece necessary since we have a similar one in Video.js now?

<body>
<div style="background-color:#eee; border: 1px solid #777; padding: 10px; margin-bottom: 20px; font-size: .8em; line-height: 1.5em; font-family: Verdana, sans-serif;">
<p>You can use /sandbox/ for writing and testing your own code. Nothing in /sandbox/ will get checked into the repo, except files that end in .example (so don't edit or add those files). To get started make a copy of index.html.example and rename it to index.html.</p>
<pre>cp sandbox/focus-visible.html.example sandbox/focus-visible.html</pre>
Copy link
Member

Choose a reason for hiding this comment

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

we really need to update this text, npm start will automatically copy these files over from .example if they don't already exist.

<video id="vid1" class="video-js vjs-default-skin" controls preload="auto" width="640" height="264"
poster="http://vjs.zencdn.net/v/oceans.png"
data-setup='{"controlBar": {"volumePanel": {"inline": false}}}'>
<!-- <source src="http://wms.shared.streamshow.it/canale8/canale8/playlist.m3u8" type="application/x-mpegURL"> -->
Copy link
Member

Choose a reason for hiding this comment

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

can this line be removed?

@gkatsev
Copy link
Member

gkatsev commented Oct 24, 2018

Looks like the package-lock hasn't been updated, can you update it with npm 6.4.1?

@@ -52,3 +52,7 @@
border: none;
visibility: hidden;
}

.video-js *:focus:not(.focus-visible) {
Copy link
Member

Choose a reason for hiding this comment

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

does the polyfill require the usage of the .focus-visible class? We probably want to have both selectors in that case.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, according to the polyfill doc. This class is needed.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, cool, didn't realize. Yeah, let's just do both, then eventually we can remove this one. Thanks!

Copy link
Member

@OwenEdwards OwenEdwards Oct 25, 2018

Choose a reason for hiding this comment

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

If you're going to do this (which makes sense because the focus-visible polyfill can only apply a .focus-visible class, not a :focus-visible pseudo-class, I think you need to include the syntax I had in my example:

.js-focus-visible .video-js *:focus:not(.focus-visible) {
  outline: none;
}

Without the .js-focus-visible it's going to remove the focus outline if the developer doesn't include the polyfill, which is exactly what we want to avoid.

For example, see https://deploy-preview-5483--videojs-docs.netlify.com/test-example/index.html and use keyboard-only operation.

Copy link
Member

Choose a reason for hiding this comment

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

^^^ That comment should have been a review

@gkatsev
Copy link
Member

gkatsev commented Oct 24, 2018

@gkatsev
Copy link
Member

gkatsev commented Oct 24, 2018

Actually, it's weird but I'm not seeing the outline when using the keyboard which is kind of weird. I'd expect to still see it then.

@gkatsev
Copy link
Member

gkatsev commented Oct 24, 2018

Aah, makes sense. Totally missed that. I guess either swap it out for

<script src="https://unpkg.com/focus-visible"></script>

or edit the build file https://github.com/videojs/video.js/blob/master/build/generate-example.js

The updating the url is probably easiest.

@gkatsev
Copy link
Member

gkatsev commented Oct 24, 2018

Loading in the polyfill manually made it work beautifully.

@gjanblaszczyk
Copy link
Member Author

Great but maybe I should change the focus-visible polyfill script src to https://unpkg.com/focus-visible on the focus-visible example page and remove focus-visible polyfill from the node package.json file. I guess better to have less dependency. What do you think?

@gkatsev
Copy link
Member

gkatsev commented Oct 24, 2018

Sounds good.

Copy link
Member

@gkatsev gkatsev left a comment

Choose a reason for hiding this comment

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

🎉

Copy link
Member

@OwenEdwards OwenEdwards left a comment

Choose a reason for hiding this comment

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

See my note on the need for the .js-focus-visible class in the CSS selector.

@@ -52,3 +52,7 @@
border: none;
visibility: hidden;
}

.video-js *:focus:not(.focus-visible) {
Copy link
Member

Choose a reason for hiding this comment

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

^^^ That comment should have been a review

@gkatsev
Copy link
Member

gkatsev commented Oct 25, 2018

Oh, yeah, I'll add it in when I merge if @gjanblaszczyk doesn't get to it first.

@gkatsev gkatsev merged commit b8fe624 into videojs:master Oct 25, 2018
@welcome
Copy link

welcome bot commented Oct 25, 2018

Congrats on merging your first pull request! 🎉🎉🎉

@gkatsev
Copy link
Member

gkatsev commented Oct 25, 2018

Thanks @gjanblaszczyk!

@gjanblaszczyk
Copy link
Member Author

np @gkatsev

gkatsev pushed a commit that referenced this pull request Oct 31, 2018
Add support for focus-visible so that mouse-users don't need to see focus outlines but keyboard and Screen Reader users still do. It includes both the standard selector and the selector intended to work with the polyfill: https://github.com/WICG/focus-visible.
The polyfill is *not* included in Video.js and must be included on the page separately.

Fixes #5474.
@gkatsev gkatsev mentioned this pull request Dec 18, 2018
4 tasks
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.

None yet

4 participants