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

fix: Display heading level dropdown icons and labels #52004

Merged
merged 2 commits into from
Jun 28, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
headingLevel6,
paragraph,
} from '@wordpress/icons';
import { Icon } from '@wordpress/components';

/** @typedef {import('@wordpress/element').WPComponent} WPComponent */

Expand Down Expand Up @@ -39,5 +40,9 @@ const LEVEL_TO_PATH = {
* @return {?WPComponent} The icon.
*/
export default function HeadingLevelIcon( { level } ) {
return LEVEL_TO_PATH[ level ] ?? null;
if ( LEVEL_TO_PATH[ level ] ) {
return <Icon icon={ LEVEL_TO_PATH[ level ] } />;
}
dcalhoun marked this conversation as resolved.
Show resolved Hide resolved

return null;
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ const HEADING_LEVELS = [ 1, 2, 3, 4, 5, 6 ];
*
* @return {WPComponent} The toolbar.
*/
export default function HeadingLevelDropdown( { selectedLevel, onChange } ) {
export default function HeadingLevelDropdown( {
options = HEADING_LEVELS,
value,
onChange,
} ) {
const createLevelControl = (
targetLevel,
currentLevel,
Expand All @@ -53,9 +57,9 @@ export default function HeadingLevelDropdown( { selectedLevel, onChange } ) {

return (
<DropdownMenu
icon={ <HeadingLevelIcon level={ selectedLevel } /> }
controls={ HEADING_LEVELS.map( ( index ) =>
createLevelControl( index, selectedLevel, onChange )
icon={ <HeadingLevelIcon level={ value } /> }
controls={ options.map( ( index ) =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is embarrassing, thank you.

createLevelControl( index, value, onChange )
) }
label={ __( 'Change level' ) }
/>
Expand Down
18 changes: 18 additions & 0 deletions packages/block-library/src/heading/test/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,22 @@ describe( 'Heading block', () => {
// Assert
expect( getEditorHtml() ).toMatchSnapshot();
} );

it( 'change level dropdown displays active selection', async () => {
// Arrange
const screen = await initializeEditor();
await addBlock( screen, 'Heading' );
const headingBlock = await getBlock( screen, 'Heading' );

// Act
fireEvent.press( headingBlock );
fireEvent.press( screen.getByLabelText( 'Change level' ) );

// Assert
expect(
within( screen.getByLabelText( 'Heading 2' ) ).getByTestId(
'bottom-sheet-cell-selected-icon'
)
).toBeVisible();
} );
} );
1 change: 1 addition & 0 deletions packages/components/src/mobile/bottom-sheet/cell.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ class BottomSheetCell extends Component {
<Icon
icon={ check }
fill={ platformStyles.isSelected.color }
testID="bottom-sheet-cell-selected-icon"
/>
) }
{ showValue && getValueComponent() }
Expand Down