How to use the @microsoft/fast-web-utilities.KeyCodes.home function in @microsoft/fast-web-utilities

To help you get started, we’ve selected a few @microsoft/fast-web-utilities examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github microsoft / fast-dna / packages / fast-components-react-base / src / context-menu / context-menu.spec.tsx View on Github external
test("should move focus the first focusable element when the home key is pressed", (): void => {
        const rendered: any = mount(
            
                <div>one</div>
                <div role="menuitem">two</div>
                <div role="menuitem">three</div>
                <div role="menuitem">four</div>
            
        );

        rendered.setState({ focusIndex: 3 });

        rendered.childAt(0).simulate("keydown", { keyCode: KeyCodes.home });

        expect(rendered.state("focusIndex")).toBe(1);
    });
github microsoft / fast-dna / packages / fast-components-react-base / src / listbox / listbox.spec.tsx View on Github external
test("should select a range and move focus to beginning when ctrl-shift-home is pressed in multi-select mode", (): void =&gt; {
        const rendered: any = mount(
            
                {itemA}
                {itemB}
                {itemC}
            ,
            { attachTo: container }
        );

        rendered.childAt(0).simulate("keydown", { keyCode: KeyCodes.arrowDown });
        expect(rendered.state("focusIndex")).toBe(1);
        expect(rendered.state("selectedItems").length).toBe(0);

        rendered.childAt(0).simulate("keydown", {
            keyCode: KeyCodes.home,
            shiftKey: true,
            ctrlKey: true,
        });
        expect(rendered.state("focusIndex")).toBe(0);
        expect(rendered.state("selectedItems").length).toBe(2);
        expect(rendered.state("selectedItems")[0].id).toBe("a");
        expect(rendered.state("selectedItems")[1].id).toBe("b");
        let element: HTMLElement = document.getElementById("a");
        expect(element.getAttribute("aria-selected")).toBe("true");
        element = document.getElementById("b");
        expect(element.getAttribute("aria-selected")).toBe("true");

        rendered.detach();
    });
github microsoft / fast-dna / packages / fast-components-react-base / src / listbox / listbox.spec.tsx View on Github external
test("should move focus the first focusable element when the home key is pressed", (): void =&gt; {
        const rendered: any = mount(
            
                <div>one</div>
                {itemA}
                {itemB}
                {itemC}
            ,
            { attachTo: container }
        );

        rendered.setState({ focusIndex: 3 });
        expect(rendered.state("focusIndex")).toBe(3);

        rendered.childAt(0).simulate("keydown", { keyCode: KeyCodes.home });
        expect(rendered.state("focusIndex")).toBe(1);

        rendered.detach();
    });
github microsoft / fast-dna / packages / fast-components-react-base / src / tabs / tabs.spec.tsx View on Github external
.prop("active")
        ).toBe(false);
        expect(
            rendered
                .find(Tab.displayName)
                .at(1)
                .prop("active")
        ).toBe(false);
        expect(
            rendered
                .find(Tab.displayName)
                .at(2)
                .prop("active")
        ).toBe(true);

        tab1.simulate("keydown", { keyCode: KeyCodes.home });

        expect(
            rendered
                .find(Tab.displayName)
                .at(0)
                .prop("tabIndex")
        ).toEqual(0);
        expect(
            rendered
                .find(Tab.displayName)
                .at(1)
                .prop("tabIndex")
        ).toEqual(-1);
        expect(
            rendered
                .find(Tab.displayName)
github microsoft / fast-dna / packages / fast-navigation-generator-react / src / navigation / navigation.tsx View on Github external
this.toggleItems(dataLocation);
                        }
                        break;
                    case KeyCodes.arrowDown:
                        this.focusNextTreeItem(dataLocation);
                        break;
                    case KeyCodes.arrowUp:
                        this.focusPreviousTreeItem(dataLocation);
                        break;
                    case KeyCodes.arrowRight:
                        this.focusAndOpenTreeItems(dataLocation);
                        break;
                    case KeyCodes.arrowLeft:
                        this.focusAndCloseTreeItems(dataLocation);
                        break;
                    case KeyCodes.home:
                        this.focusFirstTreeItem();
                        break;
                    case KeyCodes.end:
                        this.focusLastTreeItem();
                        break;
                    default:
                        break;
                }
            }
        };
    };
github microsoft / fast-dna / packages / fast-components-react-base / src / tabs / tabs.spec.tsx View on Github external
.prop("active")
        ).toBe(true);
        expect(
            rendered
                .find(Tab.displayName)
                .at(1)
                .prop("active")
        ).toBe(false);
        expect(
            rendered
                .find(Tab.displayName)
                .at(2)
                .prop("active")
        ).toBe(false);

        tab1.simulate("keydown", { keyCode: KeyCodes.home });

        expect(onUpdate).toBeCalledWith(id0);

        expect(
            rendered
                .find(Tab.displayName)
                .at(0)
                .prop("tabIndex")
        ).toEqual(0);
        expect(
            rendered
                .find(Tab.displayName)
                .at(1)
                .prop("tabIndex")
        ).toEqual(-1);
        expect(