-
Notifications
You must be signed in to change notification settings - Fork 56
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
Beforematch event and hidden=until-found #511
Comments
We discussed this a bit in #306 in the past. |
Thanks for bringing this review to us. We are looking at this at our virtual face-to-face. This seems intrinsically linked to the I struggled to fully understand the use case, even having read through the earlier discussion on #306, this explainer, and the Display Locking explainer mentioned above. Would it be possible to have a clearer description of exactly what problem this is solving? One other note: " |
Also from the same virtual face-to-face review. My main concern with the proposal is somewhat captured with issue 150. The I appreciate that you're upfront listing the issues in your explainer however I didn't see good mitigation besides some ideas around scrolling specific logic. Can you provide more details as to how do you intend to stabilize this? |
(Just some logistics changes; we restructured the repo a little bit so the links have changed: All of these should be discoverable from the main display locking repo) |
Thanks for the feedback! Sorry for the slow reply, I took some time to compare with alternatives more closely and refine the explainer.
The case that is handled by
This event helps with situations such as “collapsed sections of text” or other forms of content that is hidden unless shown by a user interaction (other than scroll). This is similar to the built-in This event allows the developer to provide the ability to search through such content, notifying the page when a match is found, which in turn allows the page to do what is necessary to show the text and reveal the full contents.
Regarding a pseudo-selector: that’s a good point. Styling a specific element could be achieved with a pseudo-selector. However, we don’t think this approach will work in more complex cases where ancestor or sibling elements need to be re-styled, or interaction with frameworks or virtual scrollers. I added an alternatives section to the explainer to elaborate on this here
I do agree that there are some details to work out to mitigate this problem. In our experimentation, the only case we found in a “natural” page is that a section that expands may change layout, so the browser needs to be careful about scroll positioning. In malicious sites (or sites with unfortunate bugs), the cyclic behavior is definitely possible. I would argue that this type of behavior is already possible in most event handlers that observe DOM changes though (examples: MutationObserver, IntersectionObserver, ResizeObserver, scroll event listeners (especially with scroll anchoring)). One proposal for mitigating this is to allow the user-agent to “give up” after some number of tries. So in the example of find-in-page, this would mean something like
This will be possible because the source of the find-in-page is always a user agent action, not a script-driven action. For that reason also, the spec could suggest the user agent apply such a mitigation but not spell out the mitigation in detail. |
@josepharhar Sorry for the slow response!
I think some more fleshed out use cases, separated out from the example code, would help guide the review here. For example, the introduction mentions 'visibility: hidden' subtrees, but that is not covered in a use case. Given 'visibility: hidden' subtrees are usually expected to be hidden from the user in every way, this seems worth expanding on. As an author, when would I use Similarly, several of the alternatives mention "Doesn't allow "unlocked"
Couldn't you use |
So this is
So I see that the cons section lists "There is no way in CSS to say "change my style if a descendant has a pseudo class on it.". I am not a CSS expert but maybe this should be added? @plinss @atanassov
How exactly do you do this? If it was collapsed before, how do you know the intended position before laying it out? |
Thanks for taking another look at this!
I have no other examples. The intent of the feature is to allow searching into hidden content, and to allow revealing the content when a match is found. Hidden-matchable and the beforematch event make this possible when used together, and without both of them, we won’t have the desired feature. The details element could also benefit from beforematch since it has revealable hidden content, but it wouldn’t make a ton of sense to have it be the only way to use beforematch. After thinking about it some more, I agree with these considerations: I think that we should combine the proposals for content-visibility:hidden-matchable and the beforematch event. Should I edit the title and description of this issue? Here is the explainer for hidden-matchable.
The explainer may have been a bit misleading - visibility: hidden text is not and will not be available to find-in-page. I’ll update the explainer to make it less misleading.
content-visibility: hidden-matchable hides content the same way visibility: hidden does. The native find-in-page feature can fire the beforematch event on hidden-matchable content if a match is found, but we don't think it's possible for other find-in-page mechanisms built on top of the AX tree to fire this event. I don’t have a lot of expertise in assistive technologies, but I think that they don't have full access to the DOM and styles, so they would not be able to fire the beforematch event and scroll like find-in-page does.
In a previous iteration of this feature, we had content-visibility: hidden-matchable without the beforematch event. When the user searched for text inside of these sections, the section would get revealed without the page being explicitly notified, and the style would remain hidden-matchable. In this case, there is no way for the page to make the selection collapsed again, which is desired in use cases which look similar to a details element where the user clicks on the title or arrow of the collapsible section to toggle the collapsing. To talk about a specific example, imagine a mobile wikipedia page with collapsed sections. Suppose you find some word, foo, in a collapsed section. This section would have to be revealed in some way. If the user then dismisses the find-in-page dialog, or continues onto the next match, then this section should remain open. However, either the browser makes this state of being expanded sticky (meaning that the script can’t collapse the section anymore), or the section collapses automatically when there is no longer a match (which is not desired behavior). This case can be addressed by firing a beforematch event and letting script design on the correct course of action.
It seems like there isn’t a way to listen for changes in pseudoclasses. This means that it’s unclear when to run this querySelector / script. Even if there was a way you could with a MutationObserver, I think that a DOM event like beforematch is more ergonomic. It would also be challenging to make sure the timing works out well - right now, we make sure that the beforematch event is fired before find-in-page tries to scroll so that script can reveal the content before it gets scrolled to. However, if the page were to try to do this with a MutationObserver, trying to time the find-in-page scroll would be more challenging.
We are only looking at the DOM position, which is independent of the layout/position on screen. If the matching text is removed from the DOM, then we will continue the search and fire the beforematch event again. |
Yeah, it seems like these two APIs really form one conceptual API together. It would make sense to combine the explainers as well, since one doesn't really work without the other. That combined explainer could use the Wikipedia mobile page example as an end to end example illustrating how to use the two APIs in conjunction to create a good user experience.
This is a great example. Are there any other kinds of interactions you had in mind while designing these APIs? To flesh this out a little more, you might add some example code like: <h2>Cultural references</h2>
<section class="locked">
Octopus ...
</section> So what I'm interested in here is the full flow, from loading the page, to matching "Octopus", to the section being closed again. What is the goal state here? I'm guessing it's something like:
Is that the flow you're designing for? If so: what happens at step 4? How does the Also: at step 3, is it implied that the author must write code to remove the |
Done: WICG/display-locking#184
No, we don't have any other interactions in mind. Collapsible sections is our use case of interest.
This seems pretty similar to the example code I already have in the explainer, right...?
Yes
At least for the wikipedia example and other things that look like details elements, the user would click the heading to collapse the section again. The beforematch event does not specifically enable the behavior of clicking the title to collapse the section.
Yes |
After an internal privacy review, we have decided to add some mitigations which restrict the situations where beforematch can be fired. I am updating the explainer here: WICG/display-locking#185 |
I just posted about this feature in whatwg and csswg: |
As far as I understand, the user has to reveal the content immediately when a match is found, which might result in content shifting around. Especially I might be typing "icecream" really fast, making a section with the text "ice" show and then unmatch because it didn't contain "icecream". Should there be a bit if grace period, like find-in-page text only triggering an event when the user has made a small pause, like say 50-100ms? |
After several discussions at the CSSWG, they are OK with the new content-visibility:hidden-matchable property if the TAG approves it as well.
I think that the grace period could be implemented later as a separate feature for find-in-page because the same problem already exists without this feature: when you start typing a word, Chrome will try to find everything starting with the very first letter you type, which can slow down the page and/or jump around unexpectedly. Safari, however, has a delay already implemented, and it would exist as part of the browser’s find-in-page UI instead of being something implemented in the rendering engine like this feature is. |
@kenchris, @alice and myself took another pass reviewing the final proposal of the feature during our "Kronos" VF2F. One important question that came up during the review is whether we have verified that this new way of making content hidden is handled correctly per the Name Computation algorithm. Since this feature makes content hidden our expectation is that the behavior will be similar to that of Specifically, that an <input aria-labelledby="a-label">
<div style="content-visibility: hidden-matchable">
<span id="a-label">This should be the label of the above input</span>
</div> Thank you for working with us. |
Thanks for the review!
Thanks for the suggestion! I tested out the current implementation in chromium and it works with Mac VoiceOver. I am writing a test here, but unfortunately I don't think there is currently a way to get the appropriate accessibility information in WPT - the test I made uses chromium-specific testing features. I filed a bug on WPT about it here. |
FYI this is now an HTML attribute ( |
This was asked for here [1]. Hopefully we can actually upstream it to WPT once a replacement for content_shell's accessibilityController is exposed in WPT [2]. [1] w3ctag/design-reviews#511 (comment) [2] web-platform-tests/wpt#27374 Change-Id: Idc2b610c3b7a52042c3bbecc4689124f78a2be91 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2657063 Reviewed-by: vmpstr <vmpstr@chromium.org> Commit-Queue: Joey Arhar <jarhar@chromium.org> Cr-Commit-Position: refs/heads/master@{#848261} GitOrigin-RevId: 59f6ff500d33ce6f0df48df19348b1ce2445e63e
Hello TAG!
I'm requesting a TAG review of the beforematch event.
The beforematch event allows developers to display content to the user in response to the following actions:
The event is fired at render timing before these actions scroll the page. The event is fired on the element which contains the text, or in the case of element fragment navigation, whichever element has the target id.
Further details:
We'd prefer the TAG provide feedback as (please delete all but the desired option):
🐛 open issues in our GitHub repo for each point of feedback
The text was updated successfully, but these errors were encountered: