Fixes #7303 - Panel: When IsHiddenOnDismiss is true, Focus does not automatically enter Panel and is not returned when Panel is dismissed#7362
Conversation
packages/office-ui-fabric-react/src/components/Panel/Panel.base.tsx
Outdated
Show resolved
Hide resolved
|
atneik
left a comment
There was a problem hiding this comment.
Looks good to me. But I am not sure about updating the default for forceFocusInsideTrap to true, as it might be a breaking change. Even though it might be a right thing to do, we might just have to wait until it is depreciated.
|
|
||
| if (!prevForceFocusInsideTrap && newForceFocusInsideTrap) { | ||
| // Transition from forceFocusInsideTrap disabled to enabled. Emulate what happens when a FocusTrapZone gets mounted | ||
| FocusTrapZone._focusStack.push(this); |
There was a problem hiding this comment.
FocusTrapZone._focusStack.push(this); [](start = 6, length = 37)
Seems a little odd that we are not pushing every time we are going to bringFocusIntoZone. Is that expected?
There was a problem hiding this comment.
I looked closer into this. We do push every time before going into bringFocusIntoZone; however, the first _focusStack.push happens in componentWillMount(), so it's not immediately noticeable.
I looked through the code and I don't think there's a reason it NEEDS to be in componentWillMount() as opposed to componentDidMount(), so I'm bringing the _focusStack.push into the bringFocusIntoZone helper function.
| return this !== value; | ||
| }); | ||
| this._returnFocusToInitiator(); | ||
| } |
There was a problem hiding this comment.
This block of code is exactly the same as what's in componentWillUnmount. This should be pulled out into a helper function that both places call
There was a problem hiding this comment.
The helper function that both places call is this._returnFocusToInitiator().
I wasn't sure whether to include the FocusTrapStack logic in it or not, but I think I ultimately decided against it because I felt like "returnFocusToInitiator" was doing more than what it's name describes.
I can definitely revisit this decision though. If you feel like "bringFocusIntoZone" and "returnFocusToInitiator" implies the FocusTrapStack logic, then I can bring those pieces of logic into the common function
There was a problem hiding this comment.
Ok, I'm bringing the _focusStack removing logic into returnFocusToInitator() as well
50454e4 to
263451f
Compare
LevnLime
left a comment
There was a problem hiding this comment.
Responded to code review comments
| return this !== value; | ||
| }); | ||
| this._returnFocusToInitiator(); | ||
| } |
There was a problem hiding this comment.
The helper function that both places call is this._returnFocusToInitiator().
I wasn't sure whether to include the FocusTrapStack logic in it or not, but I think I ultimately decided against it because I felt like "returnFocusToInitiator" was doing more than what it's name describes.
I can definitely revisit this decision though. If you feel like "bringFocusIntoZone" and "returnFocusToInitiator" implies the FocusTrapStack logic, then I can bring those pieces of logic into the common function
|
|
||
| if (!prevForceFocusInsideTrap && newForceFocusInsideTrap) { | ||
| // Transition from forceFocusInsideTrap disabled to enabled. Emulate what happens when a FocusTrapZone gets mounted | ||
| FocusTrapZone._focusStack.push(this); |
There was a problem hiding this comment.
I looked closer into this. We do push every time before going into bringFocusIntoZone; however, the first _focusStack.push happens in componentWillMount(), so it's not immediately noticeable.
I looked through the code and I don't think there's a reason it NEEDS to be in componentWillMount() as opposed to componentDidMount(), so I'm bringing the _focusStack.push into the bringFocusIntoZone helper function.
| return this !== value; | ||
| }); | ||
| this._returnFocusToInitiator(); | ||
| } |
There was a problem hiding this comment.
Ok, I'm bringing the _focusStack removing logic into returnFocusToInitator() as well
packages/office-ui-fabric-react/src/components/Panel/Panel.base.tsx
Outdated
Show resolved
Hide resolved
|
🎉 Handy links: |
Description of changes
Please see Issue#7303 for full background explanation of the issue.
FocusTrapZone already has a "forceFocusInsideTrap" property, which the Panel sets and unsets to implement isHiddenOnDismiss. However, the feature is incomplete.
This change adds logic so that when the forceFocusInsideTrap property transitions from false to true, then bring focus into the FocusTrapZone just like if we were mounting the FocusTrapZone.
Conversely, when the forceFocusInsideTrap property transitions from true to false, return focus back outside the FocusTrapZone just like we are unmounting the FocusTrapZone.
There is also a minor change to Panel to default forceFocusInsideTrap to true like the description claims it should be.
Focus areas to test
Panel when isHiddenOnDismiss is set
FocusTrapZone
Known issues observed, but NOT being addressed by this change
Microsoft Reviewers: Open in CodeFlow