Skip to content

Commit c4973ad

Browse files
Add StaticLabel component to TabsList for improved tab label rendering
1 parent 3e8e4f5 commit c4973ad

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

packages/block-library/src/tab/tabs-list.js

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,32 @@ import clsx from 'clsx';
99
import { __, sprintf } from '@wordpress/i18n';
1010
import { RichText } from '@wordpress/block-editor';
1111
import { decodeEntities } from '@wordpress/html-entities';
12+
import { RawHTML } from '@wordpress/element';
1213

1314
/**
1415
* Internal dependencies
1516
*/
1617
import slugFromLabel from './slug-from-label';
1718

19+
function StaticLabel( { label, index } ) {
20+
if ( label ) {
21+
return (
22+
<span>
23+
<RawHTML>{ decodeEntities( label ) }</RawHTML>
24+
</span>
25+
);
26+
}
27+
return (
28+
<span>
29+
{ sprintf(
30+
/* translators: %d is the tab index + 1 */
31+
__( 'Tab %d' ),
32+
index + 1
33+
) }
34+
</span>
35+
);
36+
}
37+
1838
export default function TabsList( {
1939
siblingTabs,
2040
currentClientId,
@@ -89,14 +109,9 @@ export default function TabsList( {
89109
onChange={ onLabelChange }
90110
/>
91111
) : (
92-
<RichText.Content
93-
value={ decodeEntities( siblingLabel ) }
94-
tagName="span"
95-
placeholder={ sprintf(
96-
/* translators: %d is the tab index + 1 */
97-
__( 'Tab %d…' ),
98-
index + 1
99-
) }
112+
<StaticLabel
113+
label={ siblingLabel }
114+
index={ index }
100115
/>
101116
) }
102117
</button>

0 commit comments

Comments
 (0)