-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
FocusTrapZone: port most tests to cypress #21741
Merged
Merged
Changes from 7 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
5045e52
FocusTrapZone: port most tests to cypress
ecraig12345 ea0baa3
fix e2e scopes
ecraig12345 b23e6d4
make tests more realistic and improve comments
ecraig12345 092b312
make focus stack test more realistic
ecraig12345 d2a17f0
make tests more reliable in headless mode
ecraig12345 3b164cb
cypress: save screenshots on local headless runs
ecraig12345 e2f5677
update examples
ecraig12345 463f69f
move e2e utils to common location
ecraig12345 51b4397
story style updates
ecraig12345 7d4930c
fix checks for nothing focused
ecraig12345 9ff5d82
PR feedback
ecraig12345 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 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
72 changes: 72 additions & 0 deletions
72
packages/react-examples/src/react/FocusTrapZone/e2e/FocusTrapZone.FocusStack.stories.tsx
This file contains 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,72 @@ | ||
import * as React from 'react'; | ||
import { FocusTrapZone, mergeStyles } from '@fluentui/react'; | ||
import { useGlobal } from './shared'; | ||
|
||
// make the example a little easier to visually follow when debugging | ||
const rootClass = mergeStyles({ | ||
'> div': { | ||
// target all child FTZ roots | ||
border: '2px dashed blue', | ||
padding: 10, | ||
margin: 10, | ||
button: { | ||
display: 'inline-block', | ||
marginLeft: 10, | ||
}, | ||
}, | ||
'*:focus': { outline: '2px dashed red' }, | ||
}); | ||
|
||
/** | ||
* It maintains a proper stack of FocusTrapZones as more are mounted/unmounted | ||
*/ | ||
export const FocusStack = () => { | ||
// Whether to render each FocusTrapZone | ||
const [shouldRender, setShouldRender] = React.useState([true, false, false, false, false]); | ||
|
||
const updateFTZ = (num: 1 | 2 | 3 | 4, newValue: boolean) => { | ||
setShouldRender(prevValues => { | ||
const newValues = [...prevValues]; | ||
newValues[num] = newValue; | ||
return newValues; | ||
}); | ||
}; | ||
|
||
useGlobal('getFocusStack', () => FocusTrapZone.focusStack); | ||
|
||
return ( | ||
<div className={rootClass}> | ||
<FocusTrapZone id="ftz0"> | ||
ftz0 | ||
<button onClick={() => updateFTZ(1, true)}>add ftz1</button> | ||
<button onClick={() => updateFTZ(3, true)}>add ftz3</button> | ||
<button onClick={() => updateFTZ(4, true)}>add ftz4</button> | ||
</FocusTrapZone> | ||
|
||
{shouldRender[1] && ( | ||
<FocusTrapZone id="ftz1"> | ||
ftz1 | ||
<button onClick={() => updateFTZ(2, true)}>add ftz2</button> | ||
</FocusTrapZone> | ||
)} | ||
{shouldRender[2] && ( | ||
<FocusTrapZone id="ftz2"> | ||
ftz2 | ||
<button onClick={() => updateFTZ(1, false)}>remove ftz1</button> | ||
<button onClick={() => updateFTZ(2, false)}>remove ftz2</button> | ||
</FocusTrapZone> | ||
)} | ||
{shouldRender[3] && ( | ||
<FocusTrapZone id="ftz3" forceFocusInsideTrap={false}> | ||
ftz3 | ||
<button onClick={() => updateFTZ(3, false)}>remove ftz3</button> | ||
</FocusTrapZone> | ||
)} | ||
{shouldRender[4] && ( | ||
<FocusTrapZone id="ftz4" disabled> | ||
ftz4 | ||
</FocusTrapZone> | ||
)} | ||
</div> | ||
); | ||
}; |
36 changes: 36 additions & 0 deletions
36
...ages/react-examples/src/react/FocusTrapZone/e2e/FocusTrapZone.ImperativeFocus.stories.tsx
This file contains 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,36 @@ | ||
import * as React from 'react'; | ||
import { FocusZone, FocusTrapZone, mergeStyles, IFocusTrapZone } from '@fluentui/react'; | ||
import { useGlobal, useProps } from './shared'; | ||
|
||
const rootClass = mergeStyles({ | ||
button: { | ||
height: 30, | ||
width: 60, | ||
display: 'block', | ||
}, | ||
'*:focus': { outline: '2px dashed red' }, | ||
}); | ||
|
||
/** Imperatively focusing the FTZ */ | ||
export const ImperativeFocus = () => { | ||
const props = useProps(); | ||
const focusTrapZoneRef = React.useRef<IFocusTrapZone>(null); | ||
|
||
useGlobal('imperativeFocus', () => focusTrapZoneRef.current?.focus()); | ||
|
||
return ( | ||
// don't render until props have been set | ||
props && ( | ||
<div className={rootClass}> | ||
<FocusTrapZone disableFirstFocus componentRef={focusTrapZoneRef} {...props}> | ||
<button>first</button> | ||
<FocusZone> | ||
<button>mid</button> | ||
<button>last</button> | ||
</FocusZone> | ||
</FocusTrapZone> | ||
<button>after</button> | ||
</div> | ||
) | ||
); | ||
}; |
30 changes: 30 additions & 0 deletions
30
...ages/react-examples/src/react/FocusTrapZone/e2e/FocusTrapZone.NoTabbableItems.stories.tsx
This file contains 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,30 @@ | ||
import * as React from 'react'; | ||
import { FocusTrapZone, mergeStyles } from '@fluentui/react'; | ||
import { useProps } from './shared'; | ||
|
||
const rootClass = mergeStyles({ | ||
button: { height: 30, width: 60 }, | ||
'*:focus': { outline: '2px dashed red' }, | ||
}); | ||
|
||
/** | ||
* Tab and shift-tab when the FTZ contains 0 tabbable items | ||
*/ | ||
export const NoTabbableItems = () => { | ||
const props = useProps(); | ||
|
||
return ( | ||
// don't render until props have been set | ||
props && ( | ||
<div className={rootClass}> | ||
<button>before</button> | ||
<FocusTrapZone forceFocusInsideTrap {...props}> | ||
<button tabIndex={-1}>first</button> | ||
<button tabIndex={-1}>mid</button> | ||
<button tabIndex={-1}>last</button> | ||
</FocusTrapZone> | ||
<button>after</button> | ||
</div> | ||
) | ||
); | ||
}; |
32 changes: 32 additions & 0 deletions
32
packages/react-examples/src/react/FocusTrapZone/e2e/FocusTrapZone.PropValues.stories.tsx
This file contains 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,32 @@ | ||
import * as React from 'react'; | ||
import { FocusTrapZone, mergeStyles } from '@fluentui/react'; | ||
import { useProps } from './shared'; | ||
|
||
const rootClass = mergeStyles({ | ||
button: { height: 30, width: 60, display: 'block' }, | ||
'*:focus': { outline: '2px dashed red' }, | ||
}); | ||
|
||
/** Respects default and explicit prop values */ | ||
export const PropValues = () => { | ||
const [buttonClicked, setButtonClicked] = React.useState(''); | ||
const props = useProps(); | ||
|
||
return ( | ||
// don't render until props have been set | ||
props && ( | ||
<div className={rootClass} onClick={ev => setButtonClicked((ev.target as HTMLButtonElement).textContent || '')}> | ||
<div id="buttonClicked">clicked {buttonClicked}</div> | ||
<button>before</button> | ||
<FocusTrapZone {...props}> | ||
<button>first</button> | ||
<button>mid</button> | ||
<button className="last-class" id="last"> | ||
last | ||
</button> | ||
</FocusTrapZone> | ||
<button>after</button> | ||
</div> | ||
) | ||
); | ||
}; |
36 changes: 36 additions & 0 deletions
36
...examples/src/react/FocusTrapZone/e2e/FocusTrapZone.TabWrappingButtonFocusZone.stories.tsx
This file contains 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,36 @@ | ||
import * as React from 'react'; | ||
import { FocusZone, FocusTrapZone, FocusZoneDirection, mergeStyles } from '@fluentui/react'; | ||
|
||
const rootClass = mergeStyles({ | ||
button: { height: 30, width: 60 }, | ||
'*:focus': { outline: '2px dashed red' }, | ||
}); | ||
|
||
/** | ||
* Tab and shift-tab wrap at extreme ends of the FTZ: | ||
* | ||
* can tab between a button and a FocusZone | ||
*/ | ||
export const TabWrappingButtonFocusZone = () => { | ||
return ( | ||
<div className={rootClass}> | ||
<FocusTrapZone forceFocusInsideTrap={false}> | ||
<div> | ||
<button>first</button> | ||
</div> | ||
<FocusZone direction={FocusZoneDirection.horizontal}> | ||
<div> | ||
<button>fzFirst</button> | ||
</div> | ||
<div> | ||
<div> | ||
<button>fzMid1</button> | ||
<button>fzMid2</button> | ||
<button>fzLast</button> | ||
</div> | ||
</div> | ||
</FocusZone> | ||
</FocusTrapZone> | ||
</div> | ||
); | ||
}; |
35 changes: 35 additions & 0 deletions
35
...xamples/src/react/FocusTrapZone/e2e/FocusTrapZone.TabWrappingFocusZoneBumpers.stories.tsx
This file contains 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,35 @@ | ||
import * as React from 'react'; | ||
import { FocusZone, FocusTrapZone, FocusZoneDirection, mergeStyles } from '@fluentui/react'; | ||
|
||
const rootClass = mergeStyles({ | ||
button: { width: 60, height: 30 }, | ||
'*:focus': { outline: '2px dashed red' }, | ||
}); | ||
|
||
/** | ||
* Tab and shift-tab wrap at extreme ends of the FTZ: | ||
* | ||
* can trap focus when FTZ bookmark elements are FocusZones, | ||
* and those elements have inner elements focused that are not the first inner element | ||
*/ | ||
export const TabWrappingFocusZoneBumpers = () => { | ||
return ( | ||
<div className={rootClass}> | ||
<button>before</button> | ||
<FocusTrapZone forceFocusInsideTrap={false}> | ||
<FocusZone direction={FocusZoneDirection.horizontal}> | ||
<button>fz1First</button> | ||
<button>fz1Mid</button> | ||
<button>fz1Last</button> | ||
</FocusZone> | ||
<button>mid</button> | ||
<FocusZone direction={FocusZoneDirection.horizontal}> | ||
<button>fz2First</button> | ||
<button>fz2Mid</button> | ||
<button>fz2Last</button> | ||
</FocusZone> | ||
</FocusTrapZone> | ||
<button>after</button> | ||
</div> | ||
); | ||
}; |
This file contains 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 | ||||
---|---|---|---|---|---|---|
|
@@ -2,42 +2,36 @@ import * as React from 'react'; | |||||
import { FocusZone, FocusTrapZone, FocusZoneDirection, mergeStyles } from '@fluentui/react'; | ||||||
|
||||||
const rootClass = mergeStyles({ | ||||||
position: 'relative', | ||||||
button: { position: 'absolute', height: 30, width: 30 }, | ||||||
'#a': { top: 0, left: 0 }, | ||||||
'#b': { top: 0, left: 30 }, | ||||||
'#c': { top: 0, left: 60 }, | ||||||
'#d': { top: 30, left: 0 }, | ||||||
'#e': { top: 30, left: 30 }, | ||||||
'#f': { top: 30, left: 60 }, | ||||||
button: { height: 30, width: 60 }, | ||||||
'*:focus': { outline: '2px dashed red' }, | ||||||
}); | ||||||
|
||||||
/** | ||||||
* Tab and shift-tab wrap at extreme ends of the FTZ: | ||||||
* | ||||||
* can tab across FocusZones with different button structures | ||||||
* can between multiple FocusZones with different button structures | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit:
Suggested change
|
||||||
*/ | ||||||
export const TabWrappingMultiFocusZone = () => { | ||||||
return ( | ||||||
<div className={rootClass}> | ||||||
<FocusTrapZone forceFocusInsideTrap={false}> | ||||||
<FocusZone direction={FocusZoneDirection.horizontal}> | ||||||
<div> | ||||||
<button id="a">a</button> | ||||||
<button>fz1First</button> | ||||||
</div> | ||||||
<div> | ||||||
<button id="b">b</button> | ||||||
<button>fz1Mid</button> | ||||||
</div> | ||||||
<div> | ||||||
<button id="c">c</button> | ||||||
<button>fz1Last</button> | ||||||
</div> | ||||||
</FocusZone> | ||||||
<FocusZone direction={FocusZoneDirection.horizontal}> | ||||||
<div> | ||||||
<div> | ||||||
<button id="d">d</button> | ||||||
<button id="e">e</button> | ||||||
<button id="f">f</button> | ||||||
<button>fz2First</button> | ||||||
<button>fz2Mid</button> | ||||||
<button>fz2Last</button> | ||||||
</div> | ||||||
</div> | ||||||
</FocusZone> | ||||||
|
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.
I think having two packages as scopes caused this PR's first build to try and run tests for deps of react-components even though react-components hadn't been built or deployed. Hopefully splitting into two steps will fix it. (Problem is it won't be possible to tell in this PR, because changing a pipeline file makes the PR build all packages.)