Skip to content

Commit eeaa14c

Browse files
authored
Delete tooltip concept from FieldLabel, convert two uses to description (#2475)
* delete tooltip concept from FieldLabel, convert two uses to description * fix instance create test * use instance name as placeholder for hostname input
1 parent 5ece6e1 commit eeaa14c

File tree

11 files changed

+35
-99
lines changed

11 files changed

+35
-99
lines changed

app/components/form/fields/FileField.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ export function FileField<
2525
id,
2626
name,
2727
label,
28-
tooltipText,
2928
control,
3029
required = false,
3130
accept,
@@ -49,7 +48,7 @@ export function FileField<
4948
return (
5049
<div>
5150
<div className="mb-2">
52-
<FieldLabel id={`${id}-label`} htmlFor={id} tip={tooltipText} optional={!required}>
51+
<FieldLabel id={`${id}-label`} htmlFor={id} optional={!required}>
5352
{label}
5453
</FieldLabel>
5554
{description && <TextInputHint id={`${id}-help-text`}>{description}</TextInputHint>}

app/components/form/fields/ListboxField.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ export type ListboxFieldProps<
2828
label?: string
2929
required?: boolean
3030
description?: string | React.ReactNode
31-
tooltipText?: string
3231
control: Control<TFieldValues>
3332
disabled?: boolean
3433
items: ListboxItem[]
@@ -48,7 +47,6 @@ export function ListboxField<
4847
label = capitalize(name),
4948
disabled,
5049
required,
51-
tooltipText,
5250
description,
5351
className,
5452
control,
@@ -65,7 +63,6 @@ export function ListboxField<
6563
<Listbox
6664
description={description}
6765
label={label}
68-
tooltipText={tooltipText}
6966
required={required}
7067
placeholder={placeholder}
7168
noItemsPlaceholder={noItemsPlaceholder}

app/components/form/fields/NumberField.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ export function NumberField<
2525
name,
2626
label = capitalize(name),
2727
units,
28-
tooltipText,
2928
description,
3029
required,
3130
...props
@@ -35,7 +34,7 @@ export function NumberField<
3534
return (
3635
<div className="max-w-lg">
3736
<div className="mb-2">
38-
<FieldLabel htmlFor={id} id={`${id}-label`} tip={tooltipText} optional={!required}>
37+
<FieldLabel htmlFor={id} id={`${id}-label`} optional={!required}>
3938
{label} {units && <span className="ml-1 text-secondary">({units})</span>}
4039
</FieldLabel>
4140
{description && (
@@ -67,7 +66,6 @@ export const NumberFieldInner = <
6766
label = capitalize(name),
6867
validate,
6968
control,
70-
tooltipText,
7169
required,
7270
id: idProp,
7371
disabled,
@@ -98,8 +96,7 @@ export const NumberFieldInner = <
9896
<NumberInput
9997
id={id}
10098
error={!!error}
101-
aria-labelledby={cn(`${id}-label`, !!tooltipText && `${id}-help-text`)}
102-
aria-describedby={tooltipText ? `${id}-label-tip` : undefined}
99+
aria-labelledby={cn(`${id}-label`)}
103100
isDisabled={disabled}
104101
maxValue={max ? Number(max) : undefined}
105102
minValue={min !== undefined ? Number(min) : undefined}

app/components/form/fields/RadioField.tsx

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,6 @@ export type RadioFieldProps<
3535
* label when using a screen reader.
3636
*/
3737
description?: string | React.ReactNode
38-
/**
39-
* Displayed in a tooltip beside the title. This field should be used
40-
* for auxiliary context that helps users understand extra context about
41-
* a field but isn't specifically required to know how to complete the input.
42-
* This is announced as an `aria-description`
43-
*
44-
* @see https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-description
45-
*/
46-
tooltipText?: string
4738
placeholder?: string
4839
units?: string
4940
control: Control<TFieldValues>
@@ -66,7 +57,6 @@ export function RadioField<
6657
name,
6758
label = capitalize(name),
6859
description,
69-
tooltipText,
7060
units,
7161
control,
7262
items,
@@ -79,7 +69,7 @@ export function RadioField<
7969
<div>
8070
<div className="mb-2">
8171
{label && (
82-
<FieldLabel id={`${id}-label`} tip={tooltipText}>
72+
<FieldLabel id={`${id}-label`}>
8373
{label} {units && <span className="ml-1 text-secondary">({units})</span>}
8474
</FieldLabel>
8575
)}
@@ -88,10 +78,7 @@ export function RadioField<
8878
</div>
8979
<RadioGroup
9080
defaultChecked={field.value}
91-
aria-labelledby={cn(`${id}-label`, {
92-
[`${id}-help-text`]: !!tooltipText,
93-
})}
94-
aria-describedby={tooltipText ? `${id}-label-tip` : undefined}
81+
aria-labelledby={`${id}-label`}
9582
onChange={(e) =>
9683
parseValue ? field.onChange(parseValue(e.target.value)) : field.onChange(e)
9784
}
@@ -130,7 +117,6 @@ export function RadioFieldDyn<
130117
name,
131118
label = capitalize(name),
132119
description,
133-
tooltipText,
134120
units,
135121
control,
136122
children,
@@ -142,7 +128,7 @@ export function RadioFieldDyn<
142128
<div>
143129
<div className="mb-2">
144130
{label && (
145-
<FieldLabel id={`${id}-label`} tip={tooltipText}>
131+
<FieldLabel id={`${id}-label`}>
146132
{label} {units && <span className="ml-1 text-secondary">({units})</span>}
147133
</FieldLabel>
148134
)}
@@ -151,8 +137,7 @@ export function RadioFieldDyn<
151137
</div>
152138
<RadioGroup
153139
defaultChecked={field.value}
154-
aria-labelledby={cn(`${id}-label`, !!tooltipText && `${id}-help-text`)}
155-
aria-describedby={tooltipText ? `${id}-label-tip` : undefined}
140+
aria-labelledby={cn(`${id}-label`)}
156141
onChange={field.onChange}
157142
name={field.name}
158143
{...props}

app/components/form/fields/TextField.tsx

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,6 @@ export interface TextFieldProps<
4242
* label when using a screen reader.
4343
*/
4444
description?: string | React.ReactNode
45-
/**
46-
* Displayed in a tooltip beside the title. This field should be used
47-
* for auxiliary context that helps users understand extra context about
48-
* a field but isn't specifically required to know how to complete the input.
49-
* This is announced as an `aria-description`, immediately following the aria-labelledby text.
50-
*
51-
* @see https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-description
52-
*/
53-
tooltipText?: string
5445
placeholder?: string
5546
units?: string
5647
validate?: Validate<FieldPathValue<TFieldValues, TName>, TFieldValues>
@@ -66,7 +57,6 @@ export function TextField<
6657
name,
6758
label = capitalize(name),
6859
units,
69-
tooltipText,
7060
description,
7161
required,
7262
...props
@@ -76,7 +66,7 @@ export function TextField<
7666
return (
7767
<div className="max-w-lg">
7868
<div className="mb-2">
79-
<FieldLabel htmlFor={id} id={`${id}-label`} tip={tooltipText} optional={!required}>
69+
<FieldLabel htmlFor={id} id={`${id}-label`} optional={!required}>
8070
{label} {units && <span className="ml-1 text-secondary">({units})</span>}
8171
</FieldLabel>
8272
{description && (
@@ -86,7 +76,7 @@ export function TextField<
8676
)}
8777
</div>
8878
{/* passing the generated id is very important for a11y */}
89-
<TextFieldInner name={name} {...props} id={id} tooltipText={tooltipText} />
79+
<TextFieldInner name={name} {...props} id={id} />
9080
</div>
9181
)
9282
}
@@ -109,7 +99,6 @@ export const TextFieldInner = <
10999
label = capitalize(name),
110100
validate,
111101
control,
112-
tooltipText,
113102
required,
114103
id: idProp,
115104
transform,
@@ -129,16 +118,10 @@ export const TextFieldInner = <
129118
type={type}
130119
error={!!error}
131120
aria-labelledby={`${id}-label ${id}-help-text`}
132-
aria-describedby={tooltipText ? `${id}-tooltipText` : undefined}
133121
onChange={(e) => onChange(transform ? transform(e.target.value) : e.target.value)}
134122
{...fieldRest}
135123
{...props}
136124
/>
137-
{tooltipText && (
138-
<div className="sr-only" id={`${id}-tooltipText`}>
139-
{tooltipText}
140-
</div>
141-
)}
142125
<ErrorMessage error={error} label={label} />
143126
</>
144127
)

app/forms/instance-create.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,8 @@ export function CreateInstanceForm() {
269269
key="bootDiskName"
270270
name="bootDiskName"
271271
label="Disk name"
272-
tooltipText="Will be autogenerated if name not provided"
272+
// TODO: would be cool to generate the name already and use it as a placeholder
273+
description="A name will be generated if left blank"
273274
required={false}
274275
control={control}
275276
disabled={isSubmitting}
@@ -624,6 +625,8 @@ const AdvancedAccordion = ({
624625
const defaultPool = siloPools.find((pool) => pool.isDefault)?.name
625626
const attachedFloatingIps = (externalIps.field.value || []).filter(isFloating)
626627

628+
const instanceName = useWatch({ control, name: 'name' })
629+
627630
const { project } = useProjectSelector()
628631
const { data: floatingIpList } = usePrefetchedApiQuery('floatingIpList', {
629632
query: { project, limit: ALL_ISH },
@@ -692,9 +695,10 @@ const AdvancedAccordion = ({
692695
<div className="py-2">
693696
<TextField
694697
name="hostname"
695-
tooltipText="Will be generated if not provided"
698+
description="Will be set to instance name if left blank"
696699
control={control}
697700
disabled={isSubmitting}
701+
placeholder={instanceName}
698702
/>
699703
</div>
700704

app/ui/lib/Combobox.tsx

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ export type ComboboxBaseProps = {
3333
label: string
3434
placeholder?: string
3535
required?: boolean
36-
tooltipText?: string
3736
ariaLabel?: string
3837
hideOptionalTag?: boolean
3938
/**
@@ -61,7 +60,6 @@ export const Combobox = ({
6160
selected,
6261
label,
6362
placeholder,
64-
tooltipText,
6563
required,
6664
hasError,
6765
disabled,
@@ -95,12 +93,7 @@ export const Combobox = ({
9593
{label && (
9694
// TODO: FieldLabel needs a real ID
9795
<div className="mb-2">
98-
<FieldLabel
99-
id="FieldLabel"
100-
as="div"
101-
tip={tooltipText}
102-
optional={!required && !hideOptionalTag}
103-
>
96+
<FieldLabel id="FieldLabel" as="div" optional={!required && !hideOptionalTag}>
10497
<Label>{label}</Label>
10598
</FieldLabel>
10699
{description && <TextInputHint id="TextInputHint">{description}</TextInputHint>}

app/ui/lib/FieldLabel.stories.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,10 @@ import { FieldLabel } from './FieldLabel'
99

1010
export const Default = () => <FieldLabel id="hi">hello world</FieldLabel>
1111

12-
export const WithTip = () => (
13-
<FieldLabel
14-
id="hi"
15-
tip="This is often used as the greeting from a new programming language"
16-
>
17-
hello world
18-
</FieldLabel>
19-
)
12+
export const WithTip = () => <FieldLabel id="hi">hello world</FieldLabel>
2013

2114
export const AsLegend = () => (
22-
<FieldLabel id="hi" tip="This component is literally a <legend> element" as="legend">
15+
<FieldLabel id="hi" as="legend">
2316
I am legend
2417
</FieldLabel>
2518
)

app/ui/lib/FieldLabel.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,10 @@
88
import cn from 'classnames'
99
import type { ElementType, PropsWithChildren } from 'react'
1010

11-
import { TipIcon } from './TipIcon'
12-
1311
interface FieldLabelProps {
1412
id: string
1513
as?: ElementType
1614
htmlFor?: string
17-
tip?: string
1815
optional?: boolean
1916
className?: string
2017
}
@@ -23,7 +20,6 @@ export const FieldLabel = ({
2320
id,
2421
children,
2522
htmlFor,
26-
tip,
2723
optional,
2824
as,
2925
className,
@@ -41,7 +37,6 @@ export const FieldLabel = ({
4137
</span>
4238
)}
4339
</Component>
44-
{tip && <TipIcon>{tip}</TipIcon>}
4540
</div>
4641
)
4742
}

app/ui/lib/Listbox.tsx

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ export interface ListboxProps<Value extends string = string> {
3838
hasError?: boolean
3939
name?: string
4040
label?: React.ReactNode
41-
tooltipText?: string
4241
description?: React.ReactNode
4342
required?: boolean
4443
isLoading?: boolean
@@ -57,7 +56,6 @@ export const Listbox = <Value extends string = string>({
5756
onChange,
5857
hasError = false,
5958
label,
60-
tooltipText,
6159
description,
6260
required,
6361
disabled,
@@ -85,12 +83,7 @@ export const Listbox = <Value extends string = string>({
8583
<>
8684
{label && (
8785
<div className="mb-2">
88-
<FieldLabel
89-
id={``}
90-
as="div"
91-
tip={tooltipText}
92-
optional={!required && !hideOptionalTag}
93-
>
86+
<FieldLabel id={``} as="div" optional={!required && !hideOptionalTag}>
9487
<Label>{label}</Label>
9588
</FieldLabel>
9689
{description && <TextInputHint id={``}>{description}</TextInputHint>}

0 commit comments

Comments
 (0)