@wordpress/compose
Version:
WordPress higher-order components (HOCs).
44 lines (29 loc) • 805 B
Markdown
React hook to be used on a dialog wrapper to enable the following behaviors:
- constrained tabbing.
- focus on mount.
- return focus on unmount.
- focus outside.
The hooks returns an array composed of the two following values:
- Type: `Object|Function`
A React ref that must be passed to the DOM element where the behavior should be attached.
- Type: `Object`
Extra props to apply to the wrapper.
```jsx
import { __experimentalUseDialog as useDialog } from '@wordpress/compose';
const MyDialog = () => {
const [ ref, extraProps ] = useDialog( {
onClose: () => console.log( 'do something to close the dialog' ),
} );
return (
<div ref={ ref } { ...extraProps }>
<Button />
<Button />
</div>
);
};
```