Skip to content

Commit

Permalink
Block Editor: Use hooks instead of HoC in 'SkipToSelectedBlock' (#59202)
Browse files Browse the repository at this point in the history
Co-authored-by: Mamaduka <[email protected]>
Co-authored-by: t-hamano <[email protected]>
  • Loading branch information
3 people authored Feb 20, 2024
1 parent ea283aa commit cc80f69
Showing 1 changed file with 10 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* WordPress dependencies
*/
import { withSelect } from '@wordpress/data';
import { useSelect } from '@wordpress/data';
import { __ } from '@wordpress/i18n';
import { Button } from '@wordpress/components';

Expand All @@ -11,7 +11,14 @@ import { Button } from '@wordpress/components';
import { store as blockEditorStore } from '../../store';
import { __unstableUseBlockRef as useBlockRef } from '../block-list/use-block-props/use-block-refs';

const SkipToSelectedBlock = ( { selectedBlockClientId } ) => {
/**
* @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/block-editor/src/components/skip-to-selected-block/README.md
*/
export default function SkipToSelectedBlock() {
const selectedBlockClientId = useSelect(
( select ) => select( blockEditorStore ).getBlockSelectionStart(),
[]
);
const ref = useBlockRef( selectedBlockClientId );
const onClick = () => {
ref.current.focus();
Expand All @@ -26,14 +33,4 @@ const SkipToSelectedBlock = ( { selectedBlockClientId } ) => {
{ __( 'Skip to the selected block' ) }
</Button>
) : null;
};

/**
* @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/block-editor/src/components/skip-to-selected-block/README.md
*/
export default withSelect( ( select ) => {
return {
selectedBlockClientId:
select( blockEditorStore ).getBlockSelectionStart(),
};
} )( SkipToSelectedBlock );
}

1 comment on commit cc80f69

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in cc80f69.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/7974152082
📝 Reported issues:

Please sign in to comment.