How to use the @microsoft/fast-web-utilities.KeyCodes.space 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-navigation-generator-react / src / navigation / navigation.spec.tsx View on Github external
managedClasses,
        };
        const rendered: any = mount();
        const triggerItem: any = rendered.find(treeItemExpandListTriggerSelector);

        triggerItem.at(0).simulate("keyup", { keyCode: KeyCodes.space });

        expect(
            rendered
                .find(treeItemExpandListTriggerSelector)
                .at(0)
                .parent()
                .props()["aria-expanded"]
        ).toEqual(true);

        triggerItem.at(0).simulate("keyup", { keyCode: KeyCodes.space });

        expect(
            rendered
                .find(treeItemExpandListTriggerSelector)
                .at(0)
                .parent()
                .props()["aria-expanded"]
        ).toEqual(false);
    });
    test("should update the state with the `dataLocation` prop if it has been passed", () => {
github microsoft / fast-dna / packages / fast-components-react-base / src / listbox-item / listbox-item.spec.tsx View on Github external
test("should call a registered callback after enter/space key is pressed", (): void => {
        const onInvoke: any = jest.fn();
        const onKeyDown: any = jest.fn();
        const rendered: any = shallow(
            
        );

        rendered.simulate("keydown", { keyCode: KeyCodes.enter, preventDefault: noop });
        rendered.simulate("keydown", { keyCode: KeyCodes.space, preventDefault: noop });

        expect(onInvoke).toHaveBeenCalledTimes(2);
        expect(onKeyDown).toHaveBeenCalledTimes(2);
    });
github microsoft / fast-dna / packages / fast-tooling-react / src / navigation / navigation.spec.tsx View on Github external
test("should collapse an expanded list if the space key has been pressed on the list trigger", () => {
        const props: any = {
            ...navigationProps,
            data: standardData,
            managedClasses,
        };
        const rendered: any = mount();
        const triggerItem: any = rendered.find(treeItemListItemSelector);

        triggerItem.at(0).simulate("keydown", { keyCode: KeyCodes.space });

        expect(
            rendered
                .find(treeItemListItemSelector)
                .at(0)
                .parent()
                .props()["aria-expanded"]
        ).toEqual(true);

        triggerItem.at(0).simulate("keydown", { keyCode: KeyCodes.space });

        expect(
            rendered
                .find(treeItemListItemSelector)
                .at(0)
                .parent()
github microsoft / fast-dna / packages / fast-tooling-react / src / navigation / navigation.spec.tsx View on Github external
const props: any = {
            ...navigationProps,
            data: standardData,
            managedClasses,
        };
        const rendered: any = mount();
        const triggerItem: any = rendered.find(treeItemListItemSelector);

        expect(
            triggerItem
                .at(0)
                .parent()
                .props()["aria-expanded"]
        ).toEqual(false);

        triggerItem.at(0).simulate("keydown", { keyCode: KeyCodes.space });

        expect(
            rendered
                .find(treeItemListItemSelector)
                .at(0)
                .parent()
                .props()["aria-expanded"]
        ).toEqual(true);
    });
    test("should collapse an expanded list if the space key has been pressed on the list trigger", () => {
github microsoft / fast-dna / packages / fast-components-react-base / src / context-menu-item / context-menu-item.spec.tsx View on Github external
test("should call a registered callback after spacebar is pressed", (): void => {
        const onInvoke: any = jest.fn();
        const rendered: any = shallow();

        rendered.simulate("keydown", { keyCode: KeyCodes.space });

        expect(onInvoke).toHaveBeenCalledTimes(1);
    });
github microsoft / fast-dna / packages / fast-components-react-base / src / listbox-item / listbox-item.spec.tsx View on Github external
test("should not call a registered callback after enter/space key is pressed because it is disabled", (): void => {
        const onInvoke: any = jest.fn();
        const onKeyDown: any = jest.fn();
        const rendered: any = shallow(
            
        );

        rendered.simulate("keydown", { keyCode: KeyCodes.enter, preventDefault: noop });
        rendered.simulate("keydown", { keyCode: KeyCodes.space, preventDefault: noop });

        expect(onInvoke).toHaveBeenCalledTimes(0);
        expect(onKeyDown).toHaveBeenCalledTimes(0);
    });
github microsoft / fast-dna / packages / fast-navigation-generator-react / src / navigation / navigation.spec.tsx View on Github external
const props: any = {
            ...navigationProps,
            data: standardData,
            managedClasses,
        };
        const rendered: any = mount();
        const triggerItem: any = rendered.find(treeItemExpandListTriggerSelector);

        expect(
            triggerItem
                .at(0)
                .parent()
                .props()["aria-expanded"]
        ).toEqual(false);

        triggerItem.at(0).simulate("keyup", { keyCode: KeyCodes.space });

        expect(
            rendered
                .find(treeItemExpandListTriggerSelector)
                .at(0)
                .parent()
                .props()["aria-expanded"]
        ).toEqual(true);
    });
    test("should collapse an expanded list if the space key has been pressed on the list trigger", () => {
github microsoft / fast-dna / packages / fast-navigation-generator-react / src / navigation / navigation.tsx View on Github external
return (e: React.KeyboardEvent): void => {
            e.preventDefault();

            if (e.target === e.currentTarget) {
                switch (e.keyCode) {
                    case KeyCodes.enter:
                    case KeyCodes.space:
                        if (e.target === e.currentTarget) {
                            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;
github microsoft / fast-dna / packages / fast-components-react-base / src / select / select.spec.tsx View on Github external
{itemA}
                {itemB}
                {itemC}
            
        );

        const select: any = rendered.find("select");
        expect(select.prop("value")).toEqual([]);
        expect(select.prop("multiple")).toBe(true);
        expect(select.prop("required")).toBe(true);
        expect(select.prop("name")).toBe("testName");
        expect(select.prop("form")).toBe("testForm");

        rendered
            .find('[displayString="a"]')
            .simulate("keydown", { keyCode: KeyCodes.space });
        expect(rendered.find("select").prop("value")).toEqual(["a"]);

        rendered
            .find('[displayString="a"]')
            .simulate("keydown", { keyCode: KeyCodes.arrowDown, shiftKey: true });
        expect(rendered.find("select").prop("value")).toEqual(["a", "b"]);
    });
github microsoft / fast-dna / packages / fast-components-react-base / src / select / select.spec.tsx View on Github external
<select>
                {itemA}
                {itemB}
                {itemC}
            </select>
        );

        expect(rendered.state("selectedItems").length).toBe(1);
        expect(onValueChange).toHaveBeenCalledTimes(0);

        rendered.simulate("click");
        expect(rendered.state("isMenuOpen")).toBe(true);

        rendered
            .find('[displayString="a"]')
            .simulate("keydown", { keyCode: KeyCodes.space });
        expect(rendered.state("selectedItems").length).toBe(1);
        expect(rendered.state("value")).toBe("a");
        expect(onValueChange).toHaveBeenCalledTimes(1);
    });