Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Site Tagline: Add levelOptions attribute to control available heading levels #64113

Merged
merged 2 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/reference-guides/core-blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,7 @@ Describe in a few words what the site is about. The tagline can be used in searc
- **Name:** core/site-tagline
- **Category:** theme
- **Supports:** align (full, wide), color (background, gradients, text), interactivity (clientNavigation), spacing (margin, padding), typography (fontSize, lineHeight), ~~html~~
- **Attributes:** level, textAlign
- **Attributes:** level, levelOptions, textAlign

## Site Title

Expand Down
4 changes: 4 additions & 0 deletions packages/block-library/src/site-tagline/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
"level": {
"type": "number",
"default": 0
},
"levelOptions": {
"type": "array",
"default": [ 0, 1, 2, 3, 4, 5, 6 ]
}
},
"example": {
Expand Down
6 changes: 2 additions & 4 deletions packages/block-library/src/site-tagline/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@ import {
import { __ } from '@wordpress/i18n';
import { createBlock, getDefaultBlockName } from '@wordpress/blocks';

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

export default function SiteTaglineEdit( {
attributes,
setAttributes,
insertBlocksAfter,
} ) {
const { textAlign, level } = attributes;
const { textAlign, level, levelOptions } = attributes;
const { canUserEdit, tagline } = useSelect( ( select ) => {
const { canUser, getEntityRecord, getEditedEntityRecord } =
select( coreStore );
Expand Down Expand Up @@ -82,8 +80,8 @@ export default function SiteTaglineEdit( {
<>
<BlockControls group="block">
<HeadingLevelDropdown
options={ HEADING_LEVELS }
value={ level }
options={ levelOptions }
onChange={ ( newLevel ) =>
setAttributes( { level: newLevel } )
}
Expand Down
3 changes: 2 additions & 1 deletion test/integration/fixtures/blocks/core__site-tagline.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"name": "core/site-tagline",
"isValid": true,
"attributes": {
"level": 0
"level": 0,
"levelOptions": [ 0, 1, 2, 3, 4, 5, 6 ]
},
"innerBlocks": []
}
Expand Down
Loading