-
Notifications
You must be signed in to change notification settings - Fork 54
fix(FocusTrapZone): Set focus into zone when inner content is lazy loaded #1505
Conversation
…ardust-ui/react into fix/focus-trap-zone-lazy-load # Please enter a commit message to explain why this merge is necessary, # especially if it merges an updated upstream into a topic branch. # # Lines starting with '#' will be ignored, and an empty message aborts # the commit.
Codecov Report
@@ Coverage Diff @@
## master #1505 +/- ##
==========================================
+ Coverage 73.21% 73.24% +0.02%
==========================================
Files 822 822
Lines 6194 6200 +6
Branches 1782 1802 +20
==========================================
+ Hits 4535 4541 +6
Misses 1654 1654
Partials 5 5
Continue to review full report at Codecov.
|
const activeElement = document.activeElement as HTMLElement | ||
// if after componentDidUpdate focus is not inside the focus trap, bring it back | ||
if (!this._root.current.contains(activeElement)) { | ||
this._bringFocusIntoZone() |
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'm not sure this is a good idea. A component can update for many reasons and I am pretty sure it's not always expected behavior to bring focus back to the zone after every update.
Is see this behavior as risky because it can cause unexpected focus jumps so I'd recommend allowing the users to configure the focus zone to add / disable this behavior. Let's wait for other opinions.
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.
@Bugaa92 this will only work if the active element (currently focused element) is not inside the focus trap container (for any reason) - focus should also be there once it is rendered.
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.
as discusse doffline - one scenario where this might not work is if the popup opens another popup with focus trap. Then if the first popup updates, it might steal focus from the second popup. Can you please test this scenario?
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.
@jurokapsiar I tested this scenario. Since inner popup is rendered on button click in the first popup without relation to the outside state, it doesn't trigger componentDidUpdate.
Maybe there could be another case that I am missing, I see fabric-ui is doing the same thing. Folks, let me know what you think.
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.
@sophieH29 can we make this behavior configurable via prop?
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've tried this case and it works
<Popup> -- with lazy load state change
<InnerPopup> -- with lazy load state change
<InnerInnerPopup> -- autocontrolled Popup
<Input>
fyi @Bugaa92 @jurokapsiar
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.
@layershifter agree, updated
Codecov Report
@@ Coverage Diff @@
## master #1505 +/- ##
==========================================
+ Coverage 73.21% 73.24% +0.02%
==========================================
Files 822 822
Lines 6194 6200 +6
Branches 1782 1802 +20
==========================================
+ Hits 4535 4541 +6
Misses 1654 1654
Partials 5 5
Continue to review full report at Codecov.
|
3 similar comments
Codecov Report
@@ Coverage Diff @@
## master #1505 +/- ##
==========================================
+ Coverage 73.21% 73.24% +0.02%
==========================================
Files 822 822
Lines 6194 6200 +6
Branches 1782 1802 +20
==========================================
+ Hits 4535 4541 +6
Misses 1654 1654
Partials 5 5
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #1505 +/- ##
==========================================
+ Coverage 73.21% 73.24% +0.02%
==========================================
Files 822 822
Lines 6194 6200 +6
Branches 1782 1802 +20
==========================================
+ Hits 4535 4541 +6
Misses 1654 1654
Partials 5 5
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #1505 +/- ##
==========================================
+ Coverage 73.21% 73.24% +0.02%
==========================================
Files 822 822
Lines 6194 6200 +6
Branches 1782 1802 +20
==========================================
+ Hits 4535 4541 +6
Misses 1654 1654
Partials 5 5
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #1505 +/- ##
==========================================
- Coverage 73.17% 73.16% -0.02%
==========================================
Files 828 828
Lines 6219 6227 +8
Branches 1802 1804 +2
==========================================
+ Hits 4551 4556 +5
- Misses 1663 1666 +3
Partials 5 5
Continue to review full report at Codecov.
|
…ardust-ui/react into fix/focus-trap-zone-lazy-load
# Conflicts: # CHANGELOG.md
} | ||
|
||
render(): JSX.Element { | ||
const { className, forceFocusInsideTrap, ariaLabelledBy } = this.props | ||
const { className, forceFocusInsideTrapOnOutsideFocus, ariaLabelledBy } = this.props |
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.
should we use these new props in popupFocusTrapBehavior?
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.
if we want it by default then probably set this prop to "true" in FocusTrapZone. But I am not sure if want this by default, maybe better to allow a user to do it through customizing the behavior
Co-Authored-By: Oleksandr Fediashov <[email protected]>
Fixes #1429
BREAKING CHANGES
Renamed prop
forceFocusInsideTrap
toforceFocusInsideTrapOnOutsideFocus
Improvements
forceFocusInsideTrapOnComponentUpdate
-false
by default- once
componentDidUpdate
called in FocusTrapZone and current focused element is outside the FTZ's container, it will grab focus and put it on the inner element1. trigger
componetDidUpdate
by using state change when new content is loaded: