Devendra174's picture
Upload folder using huggingface_hub
1e92f2d verified

Close on Escape

Allows for an ordered stack of components that carry out an action when the esc key is pressed. Each instance will carry out their onEscape action before being removed from the stack on a first-in-last-out basis.

This is useful for components such as <Dialog /> and <Popover />, particularly in flows that see multiple Dialogs that 'stack'.

Usage

To use this component, either nest it inside of an existing component or as a sibling, passing it a function as onEscape to be called when esc is pressed.

import CloseOnEscape from 'calypso/components/close-on-escape';

function closeDialog() {
    // Take care of closing this component
}

function render() {
    // Nested:

    return (
        <Dialog>
            <CloseOnEscape onEscape={ this.closeDialog } />
        </Dialog>
    );

    // Or as a sibling:
    /*
    return (
        <div>
            <CloseOnEscape onEscape={ this.closeDialog } />
            <Dialog />
        </div>
    );
    */
}

Props

onEscape

Typefunction
RequiredNo
Defaultnoop

The function to be called when esc is pressed.