-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add inside
label position to InputControl
#55977
Conversation
This change adds a new `LabelPosition` value of `inside` to `InputControl`, allowing consumers to render the label visually inside the field. Resolves #55963
@@ -33,3 +35,15 @@ export default function Label( { | |||
</LabelWrapper> | |||
); | |||
} | |||
|
|||
export function InnerLabel( { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed that, when the label position is set to inside
but the label
prop is still empty, the inner label component still renders an empty label
element, which also causes the select
element to shift slightly to the right.
I wonder if we should avoid rendering a label
at all when its contents are empty?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had the same thought/observation as @ciampo regarding the shift with an empty inside
label, but it tests well and looks good to me otherwise!
Overall, this is nice work! It probably needs some design feedback around the style of the label in the new But since #56001 seems to tackle the immediate product need, we can probably pause work on this and resume if/when we'll be needing such feature at the components level |
For the sake of completeness I've added some logic to check for the presence of a But to @ciampo's point, this can be put on hold until a wider use-case arises. Will work on #56001 to resolve the specific issue at hand. |
Flaky tests detected in cbe90bb. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/6825085894
|
Closing this, as it's no longer required. Should interest in #55963 resurface, this PR can be revisited. |
What?
This change adds a new
LabelPosition
value ofinside
toInputControl
, allowing consumers to render the label visually inside the field.Resolves #55963
Why?
As noted in #55963, a use case has come up where a field needs to visually contain its label. This is not currently possible, and as such encourages consumers to use the
prefix
prop instead. This not only means that the field is less likely to have an accessible name, as thelabel
prop may well get forgotten, but the visual label will not pass focus to the input.How?
The change adds an additional value of
inside
to theLabelPosition
enum. This is checked insideInputBase
, which renders the label element inside as appropriate. Minor changes have been made to the CSS to accommodate this, but existing labels have not changed.Prefix
values will also continue to work as before, appearing between anyinside
label and the input.Testing Instructions
This shouldn't impact existing labels, as nothing around their implementation has changed. Prefixes shouldn't change either, although the CSS controlling their appearance has been updated slightly.
To test the inner label:
InputControl
in Storybook (likely here).labelPosition
toinside
works as expectedprefix
works as expectedAdditionally:
SelectControl
in Storybook (likely here)labelPosition
toinside
works as expectedTesting Instructions for Keyboard
This change should make no difference to keyboard interaction. This can be confirmed by tabbing through the control, with and without an
inside
label. The focus should move to the input, as normal.