Remove unnecessary focus on block divs in product editor (#41436)

* Add tabIndex -1 to useWooBlockProps

* Add changelog

* Fix property name in test

* Fix test

* Update changelog

* Add ts explanation

* Fix typo
This commit is contained in:
Nathan Silveira 2023-11-16 15:31:14 -03:00 committed by GitHub
parent 8fcef3b2d3
commit 9b1e5de687
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 2 deletions

View File

@ -0,0 +1,4 @@
Significance: minor
Type: fix
New product editor: Disable focus on root blocks, fixing unnecessary tab between fields in new product editor

View File

@ -14,7 +14,7 @@ jest.mock( '@wordpress/block-editor', () => ( {
} ) );
describe( 'useWooBlockProps', () => {
it( 'should return the block props with the block id and block order attributes', () => {
it( 'should return the block props with the block id, block order attributes, and tabindex', () => {
renderHook( () =>
useWooBlockProps(
{
@ -31,6 +31,7 @@ describe( 'useWooBlockProps', () => {
expect( useBlockProps ).toHaveBeenCalledWith( {
'data-template-block-id': 'test/block',
'data-template-block-order': 30,
tabIndex: -1,
className: 'test',
} );
} );

View File

@ -17,8 +17,10 @@ export const useWooBlockProps = (
const additionalProps = {
'data-template-block-id': attributes._templateBlockId,
'data-template-block-order': attributes._templateBlockOrder,
tabIndex: -1,
...props,
};
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore the type definitions are slighly wrong. It should be possible to pass the tabIndex attribute.
return useBlockProps( additionalProps );
};