-
Notifications
You must be signed in to change notification settings - Fork 48.2k
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
Add blur() and focusLast() to fragment instances #32654
Conversation
this: FragmentInstanceType, | ||
focusOptions?: FocusOptions, | ||
) { | ||
traverseFragmentInstanceReverse( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternatively this could be a bit simpler to reuse the traverseFragmentInstance
to collect the child nodes and then loop through them applying focus. The tradeoff would be an array allocation and an additional pass through the list, though I don't expect this to get hit too hard and we'd likely break early on the second loop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mainly for code size I think it's probably worth the array allocation in this case since it's a very rare case that doesn't pay for itself.
The other reason is that if this is a very long list of items, then you might hit stack overflow since you need a recursive function for each sibling to allocate the temporary memory anyway. If we had a reverse pointers it would be another story but we don't. So you have to visit all one way or another.
Comparing: 0237295...6e80692 Critical size changesIncludes critical production bundles, as well as any change greater than 2%:
Significant size changesIncludes any change greater than 0.2%: Expand to show
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer the temporary array over the extra code and risk of stack overflow.
was added in #32465. Here we add and . I also extended to take options. will focus the first focusable element. will focus the last focusable element. We could consider a naming or even the used by test selector APIs as well. will only have an effect if the current is one of the fragment children. DiffTrain build for [c69a5fc](c69a5fc)
focus()
was added in #32465. Here we addfocusLast()
andblur()
. I also extendedfocus
to take options.focus
will focus the first focusable element.focusLast
will focus the last focusable element. We could consider afocusFirst
naming or even thefocusWithin
used by test selector APIs as well.blur
will only have an effect if the currentdocument.activeElement
is one of the fragment children.