-
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
BorderControl: Make fieldset and legend use optional #42611
BorderControl: Make fieldset and legend use optional #42611
Conversation
This facilitates avoiding nested fieldsets when used within a BorderBoxControl.
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.
Worked as advertised for me
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.
Thanks for the quick iteration! I have a question about the labelling below; otherwise, this does what it says on the title 😄
<BorderLabel | ||
label={ label } | ||
hideLabelFromVision={ hideLabelFromVision } | ||
as={ renderAsFieldset ? 'legend' : undefined } |
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'm thinking that, if this element isn't a legend
, and if it's hidden from vision, it's essentially useless, because screen readers won't announce it. On the other hand, if this is part of a split control, we do need some form of accessible labelling, otherwise there's no way of telling which side is which.
I think ideally we wouldn't render BorderLabel
at all unless it's a legend
, and would instead pass the label
value directly to the controls below, where it could be prepended to their existing labels. Would this be doable?
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'd tend to agree this should either render a fieldset + legend or nothing. Also, if there's a fieldset rendered, the legend (the label prop) should be required, as rendering an unnamed group is a bit pointless.
and would instead pass the label value directly to the controls below, where it could be prepended to their existing labels
Not sure that would be ideal, as concatenation in translatable strings is problematic for some languages and should be avoided.
The code works as expected, although I'm not sure about introducing such a specific prop that highlights an implementation detail. I'd also like to take a look at this issue from a more general point of view, as we're going to face this issue across many components (for example, soon when working on I opened #42630 to discuss the best approach moving forward. |
) : ( | ||
<StyledLabel as="legend">{ label }</StyledLabel> | ||
<StyledLabel { ...labelProps }>{ label }</StyledLabel> |
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.
To my understanding, this will render a stray <label>
element, ie. a <label>
that isn't associated with any field.
Overall, I'm not sure this component should be responsible for rendering a fieldset + legend. I'd agree with @ciampo that seems something that belongs to the implementation side. Should these kind of 'base' component only render the form controls? Thanks for creating #42630 to have a place for a broader discussion 👍 |
Thank you everyone for the reviews and feedback. 👍 I'm not clear on what the next steps should be so am inclined to put this PR on hold until the discussion in #42630 unfolds. I'll happily revisit it once we decide on a path forward. |
Closing this PR due to its age and lack of clear direction for a solution. It can be reopened if required. The root issue (#42630) will remain open as it is still important to address. |
Related:
What?
Makes rendering the
BorderControl
as afieldset
with alegend
for its label, optional.Why?
The
BorderControl
is primarily used within theBorderBoxControl
which itself should be afieldset
. This PR facilitates avoiding nested fieldsets.Further context can be found here: #42351 (comment)
How?
renderAsFieldset
prop to theBorderControl
BorderControl
to render using a fieldset/legend combo based on the new propTesting Instructions
npm run storybook:dev
BorderControl
pagediv
withlabel
renderAsFieldset
prop to true i the controlsfieldset
/legend
combo. There should also be no visual change.