restricting auto add anchor and idName to h2 in useEffect

This commit is contained in:
Antoine M 2024-07-04 10:18:30 +02:00
parent 9bc3efd77d
commit f2087f77f9
4 changed files with 4 additions and 5 deletions

View File

@ -1 +1 @@
<?php return array('dependencies' => array('react', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => '9d27f8e8aa5dbd08d34f');
<?php return array('dependencies' => array('react', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => '93c893a8f74f7da180b4');

View File

@ -62,7 +62,7 @@ function Edit({
setAttributes({
idName: anchor
});
} else if (_utilities__WEBPACK_IMPORTED_MODULE_6__.cleanString && title) {
} else if (_utilities__WEBPACK_IMPORTED_MODULE_6__.cleanString && title && headingLevel === "h2") {
setAttributes({
idName: "title-" + (0,_utilities__WEBPACK_IMPORTED_MODULE_6__.cleanString)(title)
});

File diff suppressed because one or more lines are too long

View File

@ -34,11 +34,10 @@ export default function Edit({
...blockProps
}) {
const { title, headingLevel, hasIcon, iconName, idName, anchor } = attributes;
useEffect(() => {
if (anchor) {
setAttributes({ idName: anchor });
} else if (cleanString && title) {
} else if (cleanString && title && headingLevel === "h2") {
setAttributes({
idName: "title-" + cleanString(title),
});