···
it('should not allow the dialog to be tabbable', () => {
const ref = useRef<HTMLUListElement>(null);
-
<input type="text" name="text" />
<ul ref={ref} role="dialog">
···
const [visible, setVisible] = useState(false);
const [nested, setNested] = useState(false);
const ref = useRef<HTMLUListElement>(null);
-
useDialogFocus(ref, { disabled: !visible });
-
<input type="text" name="text" onFocus={() => setVisible(true)} />
-
<ul ref={ref} role="dialog">
-
<li tabIndex={0}>Outer #1</li>
-
<li tabIndex={0} onFocus={() => setNested(true)}>Outer #2</li>
-
{nested && <InnerDialog />}
-
mount(<OuterDialog />);
-
cy.get('input').first().as('input').focus();
-
cy.focused().should('have.property.name', 'text');
-
cy.realPress('ArrowDown');
-
cy.focused().contains('Outer #1');
-
cy.realPress('ArrowDown');
-
cy.focused().contains('Outer #2');
-
// select second dialog
-
cy.realPress('ArrowDown');
-
cy.focused().contains('Inner #1');
-
cy.realPress('ArrowDown');
-
cy.focused().contains('Inner #2');
-
// remains in inner dialog
-
cy.realPress('ArrowDown');
-
cy.focused().contains('Inner #1');
-
cy.realPress(['Shift', 'Tab']);
-
cy.focused().contains('Outer #2');
-
// arrows bring us back to the inner dialog
-
cy.realPress('ArrowUp');
-
cy.focused().contains('Inner #2');
-
cy.focused().contains('after');
-
// we can't reenter the dialogs
-
cy.realPress(['Shift', 'Tab']);
-
cy.get('@input').should('have.focus');
-
it('supports nested dialogs', () => {
-
const InnerDialog = () => {
-
const ref = useRef<HTMLUListElement>(null);
-
<ul ref={ref} role="dialog">
-
<li tabIndex={0}>Inner #1</li>
-
<li tabIndex={0}>Inner #2</li>
-
const OuterDialog = () => {
-
const [visible, setVisible] = useState(false);
-
const [nested, setNested] = useState(false);
-
const ref = useRef<HTMLUListElement>(null);
-
useDialogFocus(ref, { disabled: !visible });
-
<input type="text" name="text" onFocus={() => setVisible(true)} />
<ul ref={ref} role="dialog">
<li tabIndex={0}>Outer #1</li>