Skip to content

Commit 126f713

Browse files
authored
fix(richtext-slate): localized indicator not displaying in label (#15412)
### What Fixes the localized indicator (e.g. `- en`) not appearing in field labels for **Slate** rich text fields. ### Why The `localized` param was not being passed to `FieldLabel`, so the label could not determine whether it should render a locale suffix. As a result, localized Slate fields appeared identical to non-localized fields. ### Where Destructured `localized` from the field config and pass it through to `FieldLabel` in `richtext-slate/src/field/RichText.tsx`. ### Testing Added to `test/localization/e2e.spec.ts`. Fixes #12364
1 parent fb2b602 commit 126f713

3 files changed

Lines changed: 27 additions & 8 deletions

File tree

packages/richtext-slate/src/field/RichText.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ const RichTextField: React.FC<LoadedSlateFieldProps> = (props) => {
5656
name,
5757
admin: { className, description, placeholder, readOnly: readOnlyFromAdmin } = {},
5858
label,
59+
localized,
5960
required,
6061
},
6162
leaves,
@@ -254,13 +255,13 @@ const RichTextField: React.FC<LoadedSlateFieldProps> = (props) => {
254255
toolbarRef.current?.querySelectorAll(selectors)
255256

256257
;(toolbarButtons || []).forEach((child) => {
257-
const isButton = child.tagName === 'BUTTON'
258-
const isDisabling = clickState === 'disabled'
259-
child.setAttribute('tabIndex', isDisabling ? '-1' : '0')
260-
if (isButton) {
261-
child.setAttribute('disabled', isDisabling ? 'disabled' : null)
262-
}
263-
})
258+
const isButton = child.tagName === 'BUTTON'
259+
const isDisabling = clickState === 'disabled'
260+
child.setAttribute('tabIndex', isDisabling ? '-1' : '0')
261+
if (isButton) {
262+
child.setAttribute('disabled', isDisabling ? 'disabled' : null)
263+
}
264+
})
264265
}
265266

266267
if (disabled) {
@@ -313,7 +314,7 @@ const RichTextField: React.FC<LoadedSlateFieldProps> = (props) => {
313314

314315
return (
315316
<div className={classes} style={styles}>
316-
{Label || <FieldLabel label={label} path={path} required={required} />}
317+
{Label || <FieldLabel label={label} localized={localized} path={path} required={required} />}
317318
<div className={`${baseClass}__wrap`}>
318319
<RenderCustomComponent
319320
CustomComponent={Error}

test/localization/collections/AllFields/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import type { CollectionConfig } from 'payload'
22

3+
import { slateEditor } from '@payloadcms/richtext-slate'
4+
35
import { allFieldsLocalizedSlug } from '../../shared.js'
46

57
export const AllFieldsLocalized: CollectionConfig = {
@@ -61,6 +63,12 @@ export const AllFieldsLocalized: CollectionConfig = {
6163
type: 'date',
6264
localized: true,
6365
},
66+
{
67+
name: 'richTextSlate',
68+
type: 'richText',
69+
localized: true,
70+
editor: slateEditor({}),
71+
},
6472

6573
// Localized group with localized children
6674
{

test/localization/e2e.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,16 @@ describe('Localization', () => {
765765

766766
expect(isActuallyVisible).toBe(true)
767767
})
768+
769+
test('should show locale in slate rich text field label', async () => {
770+
await page.goto(urlAllFieldsLocalized.create)
771+
772+
const richTextLabel = page.locator('label[for="field-richTextSlate"]')
773+
await expect(richTextLabel).toContainText('en')
774+
775+
await changeLocale(page, spanishLocale)
776+
await expect(richTextLabel).toContainText('es')
777+
})
768778
})
769779

770780
test('should not show publish specific locale button when no localized fields exist', async () => {

0 commit comments

Comments
 (0)