Skip to content

Commit effc1b6

Browse files
committed
feat(@clayui/language-picker): LPD-45714 Move the label for the SR to the Option component
1 parent 077031a commit effc1b6

File tree

1 file changed

+37
-36
lines changed
  • packages/clay-core/src/language-picker

1 file changed

+37
-36
lines changed

packages/clay-core/src/language-picker/index.tsx

+37-36
Original file line numberDiff line numberDiff line change
@@ -115,21 +115,21 @@ type Props = {
115115
translations?: Translations;
116116
};
117117

118-
const TranslationLabel = ({
118+
const getTranslationLabel = ({
119119
defaultLocaleId,
120-
locale,
120+
localeId,
121121
messages,
122122
translation,
123123
}: {
124124
defaultLocaleId: React.Key;
125+
localeId: React.Key;
125126
messages: Messages;
126-
locale: Item;
127127
translation: Translation;
128128
}) => {
129129
let displayType: DisplayType = 'warning';
130-
let label = messages.untranslated;
130+
let label: string = messages.untranslated;
131131

132-
if (locale.id === defaultLocaleId) {
132+
if (localeId === defaultLocaleId) {
133133
displayType = 'info';
134134
label = messages.default;
135135
} else if (translation) {
@@ -144,28 +144,9 @@ const TranslationLabel = ({
144144
}
145145
}
146146

147-
return (
148-
<>
149-
<span className="sr-only">
150-
{sub(messages.option, [
151-
locale.displayName || locale.label,
152-
label,
153-
])}
154-
</span>
155-
156-
<ClayLabel
157-
aria-hidden="true"
158-
className="c-ml-3"
159-
displayType={displayType}
160-
>
161-
{label}
162-
</ClayLabel>
163-
</>
164-
);
147+
return {displayType, label};
165148
};
166149

167-
TranslationLabel.displayName = 'Label';
168-
169150
const Trigger = React.forwardRef<HTMLButtonElement>(
170151
(
171152
{
@@ -264,8 +245,22 @@ const ClayLanguagePicker = ({
264245
triggerMessage={messages.trigger}
265246
>
266247
{(locale) => {
248+
const translationLabel = getTranslationLabel({
249+
defaultLocaleId: defaultLocaleId || locales[0]!.id,
250+
localeId: locale.id,
251+
messages,
252+
translation: translations[locale.label]!,
253+
});
254+
267255
return (
268-
<Option key={locale.id} textValue={locale.label}>
256+
<Option
257+
aria-label={sub(messages.option, [
258+
locale.displayName || locale.label,
259+
translationLabel.label,
260+
])}
261+
key={locale.id}
262+
textValue={locale.label}
263+
>
269264
<ClayLayout.ContentRow containerElement="span">
270265
<ClayLayout.ContentCol
271266
containerElement="span"
@@ -286,17 +281,23 @@ const ClayLanguagePicker = ({
286281
{hasTranslations ? (
287282
<ClayLayout.ContentCol containerElement="span">
288283
<ClayLayout.ContentSection>
289-
<TranslationLabel
290-
defaultLocaleId={
291-
defaultLocaleId ||
292-
locales[0]!.id
293-
}
294-
locale={locale}
295-
messages={messages}
296-
translation={
297-
translations[locale.label]!
284+
<ClayLabel
285+
aria-hidden="true"
286+
className="c-ml-3"
287+
displayType={
288+
translationLabel.displayType
298289
}
299-
/>
290+
>
291+
{translationLabel.label}
292+
293+
<span className="sr-only">
294+
{sub(messages.option, [
295+
locale.displayName ||
296+
locale.label,
297+
translationLabel.label,
298+
])}
299+
</span>
300+
</ClayLabel>
300301
</ClayLayout.ContentSection>
301302
</ClayLayout.ContentCol>
302303
) : null}

0 commit comments

Comments
 (0)