Skip to content

Commit

Permalink
Site Title: Add levelOptions attribute to control available heading…
Browse files Browse the repository at this point in the history
… levels (#64111)

* Add `levelOptions` attribute to the Site Title block.

Co-authored-by: ndiego <ndiego@git.wordpress.org>
Co-authored-by: youknowriad <youknowriad@git.wordpress.org>
  • Loading branch information
3 people authored Jul 31, 2024
1 parent cf21c3a commit 9ba3d14
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion docs/reference-guides/core-blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,7 @@ Displays the name of this site. Update the block, and the changes apply everywhe
- **Name:** core/site-title
- **Category:** theme
- **Supports:** align (full, wide), color (background, gradients, link, text), interactivity (clientNavigation), spacing (margin, padding), typography (fontSize, lineHeight), ~~html~~
- **Attributes:** isLink, level, linkTarget, textAlign
- **Attributes:** isLink, level, levelOptions, linkTarget, textAlign

## Social Icon

Expand Down
4 changes: 4 additions & 0 deletions packages/block-library/src/site-title/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
"type": "number",
"default": 1
},
"levelOptions": {
"type": "array",
"default": [ 0, 1, 2, 3, 4, 5, 6 ]
},
"textAlign": {
"type": "string"
},
Expand Down
6 changes: 2 additions & 4 deletions packages/block-library/src/site-title/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,12 @@ import { ToggleControl, PanelBody } from '@wordpress/components';
import { createBlock, getDefaultBlockName } from '@wordpress/blocks';
import { decodeEntities } from '@wordpress/html-entities';

const HEADING_LEVELS = [ 0, 1, 2, 3, 4, 5, 6 ];

export default function SiteTitleEdit( {
attributes,
setAttributes,
insertBlocksAfter,
} ) {
const { level, textAlign, isLink, linkTarget } = attributes;
const { level, levelOptions, textAlign, isLink, linkTarget } = attributes;
const { canUserEdit, title } = useSelect( ( select ) => {
const { canUser, getEntityRecord, getEditedEntityRecord } =
select( coreStore );
Expand Down Expand Up @@ -97,8 +95,8 @@ export default function SiteTitleEdit( {
<>
<BlockControls group="block">
<HeadingLevelDropdown
options={ HEADING_LEVELS }
value={ level }
options={ levelOptions }
onChange={ ( newLevel ) =>
setAttributes( { level: newLevel } )
}
Expand Down
1 change: 1 addition & 0 deletions test/integration/fixtures/blocks/core__site-title.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"isValid": true,
"attributes": {
"level": 1,
"levelOptions": [ 0, 1, 2, 3, 4, 5, 6 ],
"isLink": true,
"linkTarget": "_self"
},
Expand Down

0 comments on commit 9ba3d14

Please sign in to comment.