Add blur() and focusLast() to fragment instances#32654
Add blur() and focusLast() to fragment instances#32654jackpope merged 3 commits intofacebook:mainfrom
Conversation
| this: FragmentInstanceType, | ||
| focusOptions?: FocusOptions, | ||
| ) { | ||
| traverseFragmentInstanceReverse( |
There was a problem hiding this comment.
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.
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
|
sebmarkbage
left a comment
There was a problem hiding this comment.
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 extendedfocusto take options.focuswill focus the first focusable element.focusLastwill focus the last focusable element. We could consider afocusFirstnaming or even thefocusWithinused by test selector APIs as well.blurwill only have an effect if the currentdocument.activeElementis one of the fragment children.