docs(fieldlabel/form): migrates docs to storybook#3165
Conversation
|
|
🚀 Deployed on https://pr-3165--spectrum-css.netlify.app |
File metricsSummaryTotal size: 4.31 MB* 🎉 No changes detected in any packages * Size determined by adding together the size of the main file for all packages in the library.* Results are not gzipped or minified. * An ASCII character in UTF-8 is 8 bits or 1 byte. |
131fded to
753526b
Compare
| labelsAbove: { | ||
| name: "Labels above", | ||
| type: { name: "boolean" }, | ||
| labelPosition: { |
There was a problem hiding this comment.
I changed this to labelPosition because both text field and slider have similar controls called labelPosition.
| }; | ||
|
|
||
| /** | ||
| * A stacked layout with the labels above the form fields. The class `.spectrum-Form--labelPosition` is applied to the form itself. You do not need to apply a specific class to the field label because `.spectrum-FieldLabel--left` is applied to each to each [field label](/docs/components-field-label--docs) by default. |
There was a problem hiding this comment.
According to the field label docs, top labels are default, which is why the default story is changed. https://spectrum.adobe.com/page/field-label/#Label-position
When looking at textfield, if I toggle "displayFieldLabel," that also defaults to a top label.
| RightAligned.storyName = "Right-aligned"; | ||
|
|
||
| /** | ||
| * 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. |
There was a problem hiding this comment.
There's a bit about the "necessity indicator" in the Spectrum guidelines that says you can use text like "(required)" or "(optional)". I didn't see that in the S2 field label Figma file, but it is the s2 field label migration PR.
I've left that off for now, but if we want to add it now, I certainly can. I believe I'd need to add an extra control when required is true, to swap between a text and icon option.
There was a problem hiding this comment.
Cool, I was going to ask about this. I think it's fine to only show the asterisk. It might be worth mentioning that you can use text as well though? The docs site uses this wording, maybe something like this?
A Field label for a required field can display either the text “(required)”, or an asterisk.
| /** | ||
| * When the field label is too long for the available horizontal space, it wraps to form another line. | ||
| */ | ||
| export const WrappingAndRequired = Template.bind({}); |
There was a problem hiding this comment.
Do we want to keep this on the docs page, or is it enough to capture it in Chromatic? I think for the most part we've not been showing a wrapping story for components that have wrapping.
If we remove this story from the docs page, I'll keep the sentence about it wrapping, though.
There was a problem hiding this comment.
I don't mind it on the docs page, it certainly doesn't hurt to over-communicate in this case!
There was a problem hiding this comment.
There was a problem hiding this comment.
Hmm...this is a difficult one for me. It's definitely a little odd that this poor field label is just hanging out by itself, out of context. And I suppose that's my only hesitancy with adding a control, and we can use customStyles if needed (not that customStyles is shown on the docs page or in the controls table). Usually, a field label will be inside of some sort of container or form or something, right? If I go to textfield, the field label wraps at the width of the text field container. The wrapping doesn't seem to be an issue.
I don't have label controls set up for form right now, but if I go into the form.stories.js file and make up a long label, I don't actually see the text wrapping unless I use a ton of text like you did, I change the screen size, or again, pass some customStyles to form.
My gut says we don't need a control for this (namely because this component is just out of context and probably shouldn't be used on its own), but I'm open and can totally add it in if you think it's valuable.
There was a problem hiding this comment.
I could also add something like this to the WrappingAndRequired story docs:
"Implementations can pass a maximum width to the field label component using customStyles."
| label: "Interest", | ||
| id: "form-example-interests", | ||
| content: [ | ||
| (passthroughs, context) => Fieldgroup({ | ||
| layout: "horizontal", | ||
| items: [ | ||
| Checkbox({ | ||
| ...passthroughs, | ||
| label: "Kittens", | ||
| customClasses: ["spectrum-FieldGroup-item"], | ||
| }, context), | ||
| Checkbox({ | ||
| ...passthroughs, | ||
| label: "Puppies", | ||
| customClasses: ["spectrum-FieldGroup-item"], | ||
| }, context),] | ||
| }), | ||
| ], |
There was a problem hiding this comment.
I don't have default items if a user tries to use a form. Should I create some, sort of like what was mentioned for menu?
There was a problem hiding this comment.
I don't have a strong opinion on this either way, but it's probably a little smoother if you move these items up to the default args rather than being the args for the Default story, especially since you're reusing them for all the other stories.
753526b to
afa58be
Compare
afa58be to
c255830
Compare
castastrophe
left a comment
There was a problem hiding this comment.
Great additions to the test suite and nice alignment with arg naming between stories! Thanks for this update.
c255830 to
0c9cab2
Compare
rise-erpelding
left a comment
There was a problem hiding this comment.
I left a few opinions and comments, but nothing that would prevent this from being approved!
| RightAligned.storyName = "Right-aligned"; | ||
|
|
||
| /** | ||
| * 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. |
There was a problem hiding this comment.
Cool, I was going to ask about this. I think it's fine to only show the asterisk. It might be worth mentioning that you can use text as well though? The docs site uses this wording, maybe something like this?
A Field label for a required field can display either the text “(required)”, or an asterisk.
| testHeading: "Wrapped", | ||
| withStates: false, | ||
| label: "Label example with longer text that will wrap to the next line. And with an asterisk that marks it as required.", | ||
| label: "Label example with longer text that will wrap to the next line. Sometimes there is an asterisk that marks it as required.", |
There was a problem hiding this comment.
Correct, we weren't actually testing for the asterisk, but I see how it's confusing now with that text! 🫠 I don't think it's really necessary to test the required state with the wrapping label, but I could be wrong. So just in case, I removed the withStates: false. I also added in ignore: ["Wrapped"] to the disabled state data, so let me know what you think!
It should show the wrapped optional, and wrapped required (with the asterisk) now. 6bbd57f
| /** | ||
| * When the field label is too long for the available horizontal space, it wraps to form another line. | ||
| */ | ||
| export const WrappingAndRequired = Template.bind({}); |
There was a problem hiding this comment.
| label: "Interest", | ||
| id: "form-example-interests", | ||
| content: [ | ||
| (passthroughs, context) => Fieldgroup({ | ||
| layout: "horizontal", | ||
| items: [ | ||
| Checkbox({ | ||
| ...passthroughs, | ||
| label: "Kittens", | ||
| customClasses: ["spectrum-FieldGroup-item"], | ||
| }, context), | ||
| Checkbox({ | ||
| ...passthroughs, | ||
| label: "Puppies", | ||
| customClasses: ["spectrum-FieldGroup-item"], | ||
| }, context),] | ||
| }), | ||
| ], |
There was a problem hiding this comment.
I don't have a strong opinion on this either way, but it's probably a little smoother if you move these items up to the default args rather than being the args for the Default story, especially since you're reusing them for all the other stories.
0c9cab2 to
1ccaef7
Compare
1ccaef7 to
6bbd57f
Compare
6bbd57f to
d5f66c5
Compare
- adds missing stories and corresponding documentation - removes duplicate test case for right-aligned - adds customStyles to default test to match all other test styles
- adds missing stories and corresponding documentation - adds new test cases - adds fieldLabelAlignment control for left/right aligned field labels
- added documentation around the "necessity indicator" being text - included a required state for the wrapping/truncation test changes - set default args for form items
d5f66c5 to
6c3319c
Compare


Description
This continues the effort to migrate documentation from the CSS static docs site into Storybook, with a focus on
fieldlabelandform.form, and "cleaned up" forfieldlabel.formalso now has afieldLabelAlignmentcontrol, to better showcase left- or right-aligned field labels.This PR has no CSS changes, so no changeset is needed.
Jira/Specs
CSS-932
How and where has this been tested?
Please tag yourself on the tests you've marked complete to confirm the tests have been run by someone other than the author.
Validation steps
Regression testing
Validate:
Screenshots
To-do list