Skip to content

Commit 8b4511e

Browse files
authored
fix(fieldlabel): prevent required icon from appearing on its own line (#3652)
1 parent bd5271d commit 8b4511e

File tree

4 files changed

+12
-3
lines changed

4 files changed

+12
-3
lines changed

.changeset/honest-animals-stop.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@spectrum-css/fieldlabel": patch
3+
---
4+
5+
#### Fix fieldlabel required icon wrapping
6+
7+
Addresses case where fieldlabel required icon could appear on its own line when wrapping by applying text-wrap: pretty; to the parent label class and adding a non-breaking space character between the label content and required marker.

components/fieldlabel/index.css

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* Copyright 2024 Adobe. All rights reserved.
2+
* Copyright 2025 Adobe. All rights reserved.
33
*
44
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License. You may obtain a copy
@@ -85,6 +85,7 @@
8585

8686
.spectrum-FieldLabel {
8787
display: block;
88+
text-wrap: pretty;
8889
box-sizing: border-box;
8990
min-block-size: var(--mod-fieldlabel-min-height, var(--spectrum-fieldlabel-min-height));
9091

components/fieldlabel/stories/fieldlabel.stories.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ RightAligned.storyName = "Right-aligned";
104104
* Field labels for required inputs can be marked with an asterisk at the end of the label. Optional inputs would then be understood to not have the asterisk. If using the asterisk icon, do not leave any space between the label text and the start of the `<svg>` element in the markup. Extra space should not be added in addition to the inline margin.
105105
*
106106
* The field label for a required field can display either the text “(required)”, or an asterisk.
107+
*
108+
* When marking a field as required, a word-joiner character (e.g. `U+2060` or `&#8288;`) should be placed between the label text and the required marker to prevent the marker from appearing on its own line.
107109
*/
108110
export const Required = Template.bind({});
109111
Required.args = {

components/fieldlabel/stories/template.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ export const Template = ({
6060
data-testid=${ifDefined(testId)}
6161
for=${ifDefined(forInput)}
6262
>
63-
${label}
64-
${when(isRequired, () => icon)}
63+
${label?.trim()}${when(isRequired, () => html`&#8288;${icon}`)}
6564
</label>
6665
`;
6766
};

0 commit comments

Comments
 (0)