-
Notifications
You must be signed in to change notification settings - Fork 207
[CLOV-1606][BpkModalV3] Fix infinite focus redirect loop when BpkModalV3 and BpkDrawer coexist #4635
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
Open
Faye (Faye-Xiao)
wants to merge
8
commits into
main
Choose a base branch
from
CLOV-1606
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
[CLOV-1606][BpkModalV3] Fix infinite focus redirect loop when BpkModalV3 and BpkDrawer coexist #4635
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
0166bb3
[CLOV-1606][BpkModalV3] Fix infinite focus redirect loop when BpkModa…
Faye-Xiao 3331d41
chore: retrigger CI
Faye-Xiao db2c1c5
[CLOV-1606][BpkModalV3] Restore drawer focus trap after modal closes …
Faye-Xiao a91f499
[CLOV-1606][BpkModalV3] Address remaining review comments
Faye-Xiao 05d851d
[CLOV-1606] Add portalLock to prevent legacy Portal components from f…
Faye-Xiao aedb0b3
[CLOV-1606] Fix TODO comment format to put CLOV-1643 at start
Faye-Xiao 01b5419
[CLOV-1606] Guard BpkScrim and delay portalLock release to cover exit…
Faye-Xiao 5675de0
[CLOV-1606] Remove WithDrawer Storybook example
Faye-Xiao File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
packages/backpack-web/src/bpk-react-utils/src/portalLock-test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| /* | ||
| * Backpack - Skyscanner's Design System | ||
| * | ||
| * Copyright 2016 Skyscanner Ltd | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| import portalLock from './portalLock'; | ||
|
|
||
| describe('portalLock', () => { | ||
| beforeEach(() => { | ||
| portalLock.resetForTesting(); | ||
| }); | ||
|
|
||
| it('is not locked by default', () => { | ||
| expect(portalLock.isLocked()).toBe(false); | ||
| }); | ||
|
|
||
| it('is locked after lock() is called', () => { | ||
| portalLock.lock(); | ||
| expect(portalLock.isLocked()).toBe(true); | ||
| }); | ||
|
|
||
| it('is not locked after lock() then unlock()', () => { | ||
| portalLock.lock(); | ||
| portalLock.unlock(); | ||
| expect(portalLock.isLocked()).toBe(false); | ||
| }); | ||
|
|
||
| it('requires matching unlock() calls when locked multiple times (nested modals)', () => { | ||
| portalLock.lock(); | ||
| portalLock.lock(); | ||
| portalLock.unlock(); | ||
| expect(portalLock.isLocked()).toBe(true); | ||
|
|
||
| portalLock.unlock(); | ||
| expect(portalLock.isLocked()).toBe(false); | ||
| }); | ||
|
|
||
| it('does not go below zero when unlock() is called without a prior lock()', () => { | ||
| portalLock.unlock(); | ||
| expect(portalLock.isLocked()).toBe(false); | ||
|
|
||
| // A subsequent lock/unlock pair should still work correctly. | ||
| portalLock.lock(); | ||
| expect(portalLock.isLocked()).toBe(true); | ||
| portalLock.unlock(); | ||
| expect(portalLock.isLocked()).toBe(false); | ||
| }); | ||
| }); |
50 changes: 50 additions & 0 deletions
50
packages/backpack-web/src/bpk-react-utils/src/portalLock.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| /* | ||
| * Backpack - Skyscanner's Design System | ||
| * | ||
| * Copyright 2016 Skyscanner Ltd | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| // When a higher-priority overlay (e.g. BpkModalV3) is open, legacy Portal | ||
| // components (used by BpkDrawer, BpkModal, BpkDialog) should not respond to | ||
| // document click or keydown events — otherwise they start their close animation | ||
| // simultaneously with the overlay, causing a visible flash. | ||
| // | ||
| // A counter (not a boolean) is used so that nested BpkModalV3 instances each | ||
| // hold their own lock: opening a second modal increments to 2, closing it | ||
| // decrements back to 1, and the first modal's lock is still active. | ||
| // | ||
| // TODO: CLOV-1643 Remove once BpkDrawer, BpkModal, and BpkDialog are deprecated. | ||
|
|
||
| let lockCount = 0; | ||
|
|
||
| const portalLock = { | ||
| lock() { | ||
| lockCount += 1; | ||
| }, | ||
| unlock() { | ||
| if (lockCount > 0) { | ||
| lockCount -= 1; | ||
| } | ||
| }, | ||
| isLocked() { | ||
| return lockCount > 0; | ||
| }, | ||
| // Exposed for testing only — do not use in production code. | ||
| resetForTesting() { | ||
| lockCount = 0; | ||
| }, | ||
| }; | ||
|
|
||
| export default portalLock; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Tests are correct for what they test. Three concerns:
There is no test for the close path: the tests verify unscopeFocus is called on open, but there's no test asserting behaviour when the modal closes while a drawer is active. This is precisely the gap where the a11y regression lives.
scopeFocus mock is registered but never asserted in any test — suggests the author considered testing restore behavior but didn't implement it.
The beforeEach clears only unscopeFocus but not scopeFocus. If a future test for restore is added, the mock should clear both:
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.
All three points fixed:
should call focusScope.resumeFocus when modal transitions from open to closedscopeFocusmock is now also cleared inbeforeEachalongsidepauseFocusandresumeFocusunscopeFocustopauseFocus/resumeFocusto match the new implementation