Skip to content

Commit ce158b8

Browse files
authored
Nav block menu switcher - decode HTML entities and utilise accessible markup pattern (#36397)
* Decode HTML entities and utilise accessible markup pattern * Fix placeholder instance
1 parent 1d08eaf commit ce158b8

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

packages/block-library/src/navigation/edit/navigation-menu-selector.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
*/
44
import { MenuGroup, MenuItem, MenuItemsChoice } from '@wordpress/components';
55
import { useEntityId } from '@wordpress/core-data';
6-
import { __ } from '@wordpress/i18n';
6+
import { __, sprintf } from '@wordpress/i18n';
7+
import { decodeEntities } from '@wordpress/html-entities';
78

89
/**
910
* Internal dependencies
@@ -26,10 +27,18 @@ export default function NavigationMenuSelector( { onSelect, onCreateNew } ) {
2627
)
2728
)
2829
}
29-
choices={ navigationMenus.map( ( { id, title } ) => ( {
30-
value: id,
31-
label: title.rendered,
32-
} ) ) }
30+
choices={ navigationMenus.map( ( { id, title } ) => {
31+
const label = decodeEntities( title.rendered );
32+
return {
33+
value: id,
34+
label,
35+
'aria-label': sprintf(
36+
/* translators: %s: The name of a menu. */
37+
__( "Switch to '%s'" ),
38+
label
39+
),
40+
};
41+
} ) }
3342
/>
3443
</MenuGroup>
3544
<MenuGroup>

packages/block-library/src/navigation/edit/placeholder/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { useDispatch } from '@wordpress/data';
1414
import { useCallback, useState, useEffect } from '@wordpress/element';
1515
import { __ } from '@wordpress/i18n';
1616
import { navigation, Icon } from '@wordpress/icons';
17+
import { decodeEntities } from '@wordpress/html-entities';
1718

1819
/**
1920
* Internal dependencies
@@ -59,7 +60,9 @@ const ExistingMenusDropdown = ( {
5960
onClose={ onClose }
6061
key={ menu.id }
6162
>
62-
{ menu.title.rendered }
63+
{ decodeEntities(
64+
menu.title.rendered
65+
) }
6366
</MenuItem>
6467
);
6568
} ) }
@@ -75,7 +78,7 @@ const ExistingMenusDropdown = ( {
7578
onClose={ onClose }
7679
key={ menu.id }
7780
>
78-
{ menu.name }
81+
{ decodeEntities( menu.name ) }
7982
</MenuItem>
8083
);
8184
} ) }

0 commit comments

Comments
 (0)