MCPcopy Create free account
hub / github.com/adobe/react-spectrum / Example

Function Example

packages/@react-spectrum/s2/test/TreeView.test.tsx:523–578  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

521
522 it('if the previously focused item is disabled, the focus should move to the first item when coming back to the collection', async () => {
523 function Example() {
524 let [disabledBehavior, setDisabledBehavior] = useState<DisabledBehavior>('selection');
525 return (
526 <>
527 <button>Before</button>
528 <TreeView
529 aria-label="Test tree"
530 disabledBehavior={disabledBehavior}
531 disabledKeys={['school']}>
532 <TreeViewItem id="projects" textValue="Projects">
533 <TreeViewItemContent>
534 <Text>Projects</Text>o
535 <Folder />
536 <ActionMenu>
537 <MenuItem id="edit">
538 <Text>Edit</Text>
539 </MenuItem>
540 <MenuItem id="delete">
541 <Text>Delete</Text>
542 </MenuItem>
543 </ActionMenu>
544 </TreeViewItemContent>
545 </TreeViewItem>
546 <TreeViewItem id="school" textValue="School">
547 <TreeViewItemContent>
548 <Text>School</Text>o
549 <Folder />
550 <ActionMenu>
551 <MenuItem id="edit">
552 <Text>Edit</Text>
553 </MenuItem>
554 <MenuItem id="delete">
555 <Text>Delete</Text>
556 </MenuItem>
557 </ActionMenu>
558 </TreeViewItemContent>
559 <TreeViewItem id="homework-1" textValue="Homework-1" isDisabled>
560 <TreeViewItemContent>
561 <Text>Homework-1</Text>
562 <Folder />
563 <ActionMenu>
564 <MenuItem id="edit">
565 <Text>Edit</Text>
566 </MenuItem>
567 <MenuItem id="delete">
568 <Text>Delete</Text>
569 </MenuItem>
570 </ActionMenu>
571 </TreeViewItemContent>
572 </TreeViewItem>
573 </TreeViewItem>
574 </TreeView>
575 <button onClick={() => setDisabledBehavior('all')}>After</button>
576 </>
577 );
578 }
579
580 let {getAllByRole, getByRole} = render(<Example />);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected