Skip to content

Commit 008a19f

Browse files
committed
Add another example
1 parent adb9280 commit 008a19f

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

packages/react/src/TreeView/TreeView.examples.stories.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ export const TrailingActions: StoryFn = () => {
7878
return (
7979
<Box>
8080
<h2>Trailing Actions: Example with direct focus</h2>
81+
<p>Press (Command + Shift + U) to focus the trailing action button</p>
8182
<TreeView aria-label="Issues">
8283
<TreeView.Item id="item-1">Item 1</TreeView.Item>
8384
<TrailingAction id="item-2">
@@ -90,10 +91,11 @@ export const TrailingActions: StoryFn = () => {
9091
<TreeView.Item id="item-3">Item 3</TreeView.Item>
9192
</TreeView>
9293

93-
<h2>Trailing Actions: 2</h2>
94+
<h2>Trailing Actions: Example with dialog</h2>
95+
<p> Press (Command + Shift + U) to interact with the trailing action</p>
9496
<TreeView aria-label="Issues">
9597
<TreeView.Item id="item-1">Item 1</TreeView.Item>
96-
<TrailingAction id="item-2">
98+
<TrailingAction id="item-2" dialogOnOpen={true}>
9799
Item 2
98100
<TreeView.SubTree>
99101
<TreeView.Item id="item-2-sub-task-1">sub task 1</TreeView.Item>
@@ -106,14 +108,19 @@ export const TrailingActions: StoryFn = () => {
106108
)
107109
}
108110

109-
const TrailingAction: React.FC<{id: string; children: React.ReactNode}> = ({id, children}) => {
111+
const TrailingAction: React.FC<{id: string; children: React.ReactNode; dialogOnOpen?: boolean}> = ({
112+
id,
113+
dialogOnOpen,
114+
children,
115+
}) => {
110116
const [expanded, setExpanded] = React.useState(false)
111117
const [dialogOpen, setDialogOpen] = React.useState(false)
112118

113119
const btnRef = React.useRef<HTMLButtonElement>(null)
114120

115121
const mockKeyboardShortcut = (event: React.KeyboardEvent) => {
116-
btnRef.current?.focus()
122+
if (!dialogOnOpen) btnRef.current?.focus()
123+
if (dialogOnOpen) setDialogOpen(true)
117124
}
118125

119126
return (

0 commit comments

Comments
 (0)