@chakra-ui/react#Kbd JavaScript Examples

The following examples show how to use @chakra-ui/react#Kbd. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: KeyboardShortcuts.jsx    From web-client with Apache License 2.0 5 votes vote down vote up
KeyboardShortcuts = () => {
    const [modalVisible, setModalVisible] = useState(false);

    const onKeyDownListener = useCallback((ev) => {
        if (isInputElement(document.activeElement)) {
            return;
        }

        if (ev.key === '?') {
            ev.preventDefault();

            setModalVisible(!modalVisible);
        }
    }, [modalVisible]);

    const onModalClose = () => {
        setModalVisible(false);
    }

    useEffect(() => {
        document.addEventListener('keydown', onKeyDownListener);
        return () => {
            document.removeEventListener('keydown', onKeyDownListener);
        };
    }, [onKeyDownListener]);

    return <ModalDialog title="Keyboard shortcuts" visible={modalVisible} onModalClose={onModalClose} style={{ maxWidth: '500px' }}>
        <h4>General</h4>
        <ul>
            <li>
                Show/Hide keyboard shortcuts
                <Kbd>?</Kbd>
            </li>
            <li>
                Search
                <Kbd>/</Kbd>
            </li>
        </ul>
        <Divider />

        <h4>Pagination</h4>
        <ul>
            <li>
                Previous page
                <Kbd>p</Kbd>
            </li>
            <li>
                Next page
                <Kbd>n</Kbd>
            </li>
        </ul>
    </ModalDialog>
}