UNPKG

@wordpress/block-editor

Version:
34 lines (33 loc) 1.07 kB
// packages/block-editor/src/components/skip-to-selected-block/index.js import { useSelect } from "@wordpress/data"; import { __ } from "@wordpress/i18n"; import { Button } from "@wordpress/components"; import { useRef } from "@wordpress/element"; import { store as blockEditorStore } from "../../store"; import { useBlockElementRef } from "../block-list/use-block-props/use-block-refs"; import { jsx } from "react/jsx-runtime"; function SkipToSelectedBlock() { const selectedBlockClientId = useSelect( (select) => select(blockEditorStore).getBlockSelectionStart(), [] ); const ref = useRef(); useBlockElementRef(selectedBlockClientId, ref); const onClick = () => { ref.current?.focus(); }; return selectedBlockClientId ? /* @__PURE__ */ jsx( Button, { __next40pxDefaultSize: true, variant: "secondary", className: "block-editor-skip-to-selected-block", onClick, children: __("Skip to the selected block") } ) : null; } export { SkipToSelectedBlock as default }; //# sourceMappingURL=index.js.map