Keyboard Navigation

The keyboard navigation of the Switch is always available.

The Switch supports the following keyboard shortcuts:

SHORTCUTDESCRIPTION
Space keyToggles the component checked state.
Enter keyToggles the component checked state.
class App extends React.Component {
    _switch;

    componentDidMount() {
        this._switch.element.focus();
    }

    render() {
        return (
            <Switch ref={(_switch) => {this._switch = _switch }} />
        )
    }
}
ReactDOM.render(
    <App />,
    document.querySelector('my-app')
);

In this article

 /