Skip to content

Commit a3b72ee

Browse files
Mayank-Tripathi32Mayank-Tripathi32t-hamanojoedolsonamberhinds
authored
feat: added HTML element messages and integrate HTMLElementControl for button block (WordPress#70139)
Co-authored-by: Mayank-Tripathi32 <mayanktripathi32@git.wordpress.org> Co-authored-by: t-hamano <wildworks@git.wordpress.org> Co-authored-by: joedolson <joedolson@git.wordpress.org> Co-authored-by: amberhinds <alh0319@git.wordpress.org> Co-authored-by: carolinan <poena@git.wordpress.org>
1 parent b315bcf commit a3b72ee

File tree

2 files changed

+21
-0
lines changed
  • packages
    • block-editor/src/components/html-element-control
    • block-library/src/button

2 files changed

+21
-0
lines changed

packages/block-editor/src/components/html-element-control/messages.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,18 @@ import { __ } from '@wordpress/i18n';
77
* Messages providing helpful descriptions for HTML elements.
88
*/
99
export const htmlElementMessages = {
10+
a: __(
11+
'The <a> element should be used for links that navigate to a different page or to a different section within the same page.'
12+
),
1013
article: __(
1114
'The <article> element should represent a self-contained, syndicatable portion of the document.'
1215
),
1316
aside: __(
1417
"The <aside> element should represent a portion of a document whose content is only indirectly related to the document's main content."
1518
),
19+
button: __(
20+
'The <button> element should be used for interactive controls that perform an action on the current page, such as opening a modal or toggling content visibility.'
21+
),
1622
div: __(
1723
'The <div> element should only be used if the block is a design element with no semantic meaning.'
1824
),

packages/block-library/src/button/edit.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { NEW_TAB_TARGET, NOFOLLOW_REL } from './constants';
1010
import { getUpdatedLinkAttributes } from './get-updated-link-attributes';
1111
import removeAnchorTag from '../utils/remove-anchor-tag';
1212
import { useToolsPanelDropdownMenuProps } from '../utils/hooks';
13+
import { unlock } from '../lock-unlock';
1314

1415
/**
1516
* WordPress dependencies
@@ -47,6 +48,7 @@ import {
4748
useBlockEditingMode,
4849
getTypographyClassesAndStyles as useTypographyProps,
4950
useSettings,
51+
privateApis as blockEditorPrivateApis,
5052
} from '@wordpress/block-editor';
5153
import { displayShortcut, isKeyboardEvent, ENTER } from '@wordpress/keycodes';
5254
import { link, linkOff } from '@wordpress/icons';
@@ -59,6 +61,8 @@ import {
5961
import { useMergeRefs, useRefEffect } from '@wordpress/compose';
6062
import { useSelect, useDispatch } from '@wordpress/data';
6163

64+
const { HTMLElementControl } = unlock( blockEditorPrivateApis );
65+
6266
const LINK_SETTINGS = [
6367
...LinkControl.DEFAULT_LINK_SETTINGS,
6468
{
@@ -456,6 +460,17 @@ function ButtonEdit( props ) {
456460
/>
457461
</InspectorControls>
458462
<InspectorControls group="advanced">
463+
<HTMLElementControl
464+
tagName={ tagName }
465+
onChange={ ( value ) =>
466+
setAttributes( { tagName: value } )
467+
}
468+
clientId={ clientId }
469+
options={ [
470+
{ label: __( 'Default (<a>)' ), value: 'a' },
471+
{ label: '<button>', value: 'button' },
472+
] }
473+
/>
459474
{ isLinkTag && (
460475
<TextControl
461476
__next40pxDefaultSize

0 commit comments

Comments
 (0)