-
Notifications
You must be signed in to change notification settings - Fork 31
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
Allow inline fields with no visible label #2344
base: main
Are you sure you want to change the base?
Changes from all commits
1a0d7a7
e9a0bd0
83f3d0a
23bdd7b
4dcda7b
ae45f1d
d6f094a
220670e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,13 +24,11 @@ export type FieldComponentProps = { | |
*/ | ||
errorMessageList?: string[]; | ||
/** | ||
* The helper text content. | ||
* If `false` no visible label is shown. | ||
* | ||
* NOTE: the `label` prop is still required for accessibility purposes | ||
*/ | ||
hint?: string; | ||
/** | ||
* A `Link` component to provide greater context that is rendered at the end of the `hint` text | ||
*/ | ||
HintLinkComponent?: ReactElement<typeof HintLink>; | ||
hasVisibleLabel?: boolean; | ||
/** | ||
* The id of the `input` element. | ||
*/ | ||
|
@@ -55,7 +53,30 @@ export type FieldComponentProps = { | |
* The name of the `input` element. Defaults to the `id` if not set. | ||
*/ | ||
name?: string; | ||
}; | ||
} & ( | ||
| { | ||
/** | ||
* If `hasVisibleLabel` is `false` it will also hide any `hint` text and `HintLinkComponent` that is passed in | ||
*/ | ||
hasVisibleLabel?: false; | ||
hint: never; | ||
HintLinkComponent: never; | ||
} | ||
| { | ||
/** | ||
* defaults to `true` if `false` along with hiding the label it will also hide any `hint` text and `HintLinkComponent` that is passed in | ||
*/ | ||
hasVisibleLabel?: true; | ||
/** | ||
* The helper text content. | ||
*/ | ||
hint?: string; | ||
/** | ||
* A `Link` component to provide greater context that is rendered at the end of the `hint` text | ||
*/ | ||
HintLinkComponent?: ReactElement<typeof HintLink>; | ||
} | ||
); | ||
|
||
export type FieldComponentRenderProps = { | ||
ariaDescribedBy: string; | ||
|
@@ -64,3 +85,15 @@ export type FieldComponentRenderProps = { | |
id: string; | ||
labelElementId: string; | ||
}; | ||
|
||
export type ConditionalLabelProps = | ||
| { | ||
hasVisibleLabel: false; | ||
hint?: never; | ||
placeholder: string; | ||
} | ||
Comment on lines
+90
to
+94
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we expecting they at least pass in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the actual There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, my bad. I see. So we're just saying if the label is visible, not if it doesn't exist. My bad. We should also require There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| { | ||
hasVisibleLabel?: true; | ||
hint?: string; | ||
placeholder?: string; | ||
}; |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -64,6 +64,7 @@ const storybookMeta: Meta<typeof Autocomplete> = { | |||||
}, | ||||||
}, | ||||||
}, | ||||||
hasVisibleLabel: fieldComponentPropsMetaData.hasVisibleLabel, | ||||||
hint: fieldComponentPropsMetaData.hint, | ||||||
HintLinkComponent: fieldComponentPropsMetaData.HintLinkComponent, | ||||||
id: fieldComponentPropsMetaData.id, | ||||||
|
@@ -448,6 +449,20 @@ const jupiterGalileanMoons: MoonMeta[] = [ | |||||
}, | ||||||
]; | ||||||
|
||||||
export const NoVisibleLabel: StoryObj<JupiterMoonsAutocomplete> = { | ||||||
parameters: { | ||||||
docs: { | ||||||
description: { | ||||||
story: | ||||||
"TextFields with `hasVisibleLabel` set to false will not render a visible label. Although, the `label` prop is still required for accessibility purposes", | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are other spots in the docs like this as well. |
||||||
}, | ||||||
}, | ||||||
}, | ||||||
args: { | ||||||
hasVisibleLabel: false, | ||||||
}, | ||||||
}; | ||||||
|
||||||
export const ControlledMultipleAutocomplete: StoryObj<JupiterMoonsAutocomplete> = | ||||||
{ | ||||||
parameters: { | ||||||
|
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.
Is it possible we could rewrite this type to use the function overload syntax? Or have 2 different
Field
components, one with a label and one that only takesaria-labelledby
or something like that?The way the code works today, it's very confusing.
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.
This would be a pretty significant rewrite. We'd have to refactor all the form field components(that allow a non-visible label) to handle this 'correctly'