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

CSS: :focus selector effects on shadow hosts #17493

Merged
merged 6 commits into from
Sep 24, 2019

Conversation

rakina
Copy link
Contributor

@rakina rakina commented Jun 25, 2019

See whatwg/html#4731 for the spec change. PTAL :)

Copy link
Member

@domenic domenic left a comment

Choose a reason for hiding this comment

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

I am a bit worried how these tests share state between them. It would be easier to understand if they re-created entire trees each test so there were no cross-test dependencies. For example you could have factories for shadowRootDelegatesFocus and shadowRootNonDelegatesFocus.

Also although the current style is fine I'll note that you can also test el.matches(":focus") which seem a bit more direct.

@domenic
Copy link
Member

domenic commented Jun 27, 2019

Also I am wondering if CSS or components folks (e.g. @rniwa) have any opinions on whether this should be in the css/selectors directory or the shadow-dom directory or even the HTML focus directory. I am fine leaving it with the css/selectors directory myself but perhaps others have stronger preferences.

(This does not block merging as we can always move it later.)

@rniwa
Copy link
Contributor

rniwa commented Jun 27, 2019

I would've preferred to have this in shadow-dom directory given :focus is a pre-existing feature we're supporting in shadow DOM.

@rakina
Copy link
Contributor Author

rakina commented Jun 27, 2019

I am a bit worried how these tests share state between them. It would be easier to understand if they re-created entire trees each test so there were no cross-test dependencies. For example you could have factories for shadowRootDelegatesFocus and shadowRootNonDelegatesFocus.

Yeah that makes more sense - factored them out.

Also although the current style is fine I'll note that you can also test el.matches(":focus") which seem a bit more direct.

Oh hey didn't know something like that exists! thanks :)

I would've preferred to have this in shadow-dom directory given :focus is a pre-existing feature we're supporting in shadow DOM.

Moved to shadow-dom.

@rniwa
Copy link
Contributor

rniwa commented Aug 14, 2019

Alright, verified that if we implement what's being spec'ed in whatwg/html#4731, these test cases would pass, and they currently fail in WebKit.

@rakina rakina force-pushed the focusselectordelegatesFocus branch from 950005c to bfdf9b8 Compare September 20, 2019 06:17
@rakina rakina changed the title CSS: :focus selector effects on shadow host with delegatesFocus CSS: :focus selector effects on shadow hosts Sep 20, 2019
@rakina
Copy link
Contributor Author

rakina commented Sep 20, 2019

Updated the tests to expect :focus to match regardless of delegatesFocus, see whatwg/html#4731 (comment) for reasoning

Copy link
Member

@domenic domenic left a comment

Choose a reason for hiding this comment

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

LGTM with nit

@@ -60,8 +60,13 @@ function removeTabIndex(elements) {
}
}

function resetFocusOnRoot(root) {
Copy link
Member

Choose a reason for hiding this comment

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

Can we just have one function, instead of two?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

resetFocus() is already used by the sequential focus navigation tests so we still need it (unless we change it too I guess?), and we need to give the root here because we don't know the tree structure?

Copy link
Member

Choose a reason for hiding this comment

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

I see, I think I misread things. I'm OK with merging this as-is. However it could be clearer to just have function resetFocus(root = document) { /* contents of current resetFocusOnRoot */ } and update all tests to use that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh yeah sorry the non-document one is not actually used in this WPT, oops (but will be used in other ones so I think it's OK to have the general version here). Also changed it to your suggested version. Thanks!

domenic pushed a commit to whatwg/html that referenced this pull request Sep 24, 2019
Part of #2013. Note that the delegates focus flag is not consulted.

Tests: web-platform-tests/wpt#17493
@domenic domenic merged commit 0693b81 into web-platform-tests:master Sep 24, 2019
slotted.focus();
assert_true(slotted.matches(":focus"), "slotted element matches :focus");
assert_true(host.matches(":focus"), "host matches :focus");
}, `:focus applies to host with delegatesFocus=${delegatesFocus} when slotted element has focus`);
Copy link
Contributor

Choose a reason for hiding this comment

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

This is wrong. If a slotted element has a focus, then the shadow host is its parent (or ancestor). If :focus shouldn't match both the slotted element and the host of the shadow tree to which it was assigned.

I'm fixing this in #19530

zcorpan pushed a commit to whatwg/html that referenced this pull request Nov 6, 2019
Part of #2013. Note that the delegates focus flag is not consulted.

Tests: web-platform-tests/wpt#17493
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants