Focus the first attribute field when opening the modal (#39549)

* Focus the first attribute field on modal shown

* Add changelog file

* Remove setTimeout to focus the attribute dropdown field
This commit is contained in:
Maikel David Pérez Gómez 2023-08-08 10:50:11 -04:00 committed by GitHub
parent b546e4fb17
commit 8d8d315d66
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 1 deletions

View File

@ -0,0 +1,4 @@
Significance: minor
Type: add
Focus the first attribute field when opening the modal

View File

@ -2,7 +2,12 @@
* External dependencies
*/
import { __ } from '@wordpress/i18n';
import { useState, createElement, Fragment } from '@wordpress/element';
import {
useState,
createElement,
Fragment,
useEffect,
} from '@wordpress/element';
import { trash } from '@wordpress/icons';
import {
Form,
@ -201,6 +206,15 @@ export const NewAttributeModal: React.FC< NewAttributeModalProps > = ( {
}
};
useEffect( function focusFirstAttributeField() {
const firstAttributeFieldLabel =
document.querySelector< HTMLLabelElement >(
'.woocommerce-new-attribute-modal__table-row .woocommerce-attribute-input-field label'
);
firstAttributeFieldLabel?.focus();
}, [] );
return (
<>
<Form< AttributeForm >