Skip to content

Commit 1bb4472

Browse files
authored
Add for attribute for core product CI (#890)
1 parent f5d57d8 commit 1bb4472

File tree

14 files changed

+31
-17
lines changed

14 files changed

+31
-17
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2222
- `menuItemStyleContext` in `MenuContext` uses a new interface which contains "preserved icon space"-related properties
2323
- `MenuItem` renders an empty Box with the same size as the icon(s) of sibling `MenuItem's (if any)
2424
- `MenuList`, `MenuGroup` contain piece of state the tracks the size of the preserved icon space
25+
- Labels in `FieldInline` and `ButtonItem` now include the `for` attribute
2526

2627
### Fixed
2728

packages/components/src/Button/ButtonItem.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import {
3434
typography,
3535
TypographyProps,
3636
} from '@looker/design-tokens'
37+
import { useID } from '../utils'
3738

3839
export interface ButtonItemProps
3940
extends SpaceProps,
@@ -116,6 +117,7 @@ const ButtonItemComponent = forwardRef(
116117
{
117118
children,
118119
disabled,
120+
id: propsID,
119121
isControlled,
120122
name,
121123
onChange,
@@ -126,6 +128,7 @@ const ButtonItemComponent = forwardRef(
126128
ref: Ref<HTMLInputElement>
127129
) => {
128130
const [uncontrolledSelected, setUncontrolledSelected] = useState(selected)
131+
const id = useID(propsID)
129132

130133
function handleChange(e: ChangeEvent<HTMLInputElement>) {
131134
if (onChange) {
@@ -141,6 +144,7 @@ const ButtonItemComponent = forwardRef(
141144
return (
142145
<ButtonItemLabel
143146
disabled={disabled}
147+
htmlFor={id}
144148
fontFamily="brand"
145149
py="small"
146150
selected={showSelected}
@@ -150,6 +154,7 @@ const ButtonItemComponent = forwardRef(
150154
type={props.type}
151155
disabled={disabled}
152156
name={name}
157+
id={id}
153158
onChange={handleChange}
154159
checked={showSelected}
155160
value={value}

packages/components/src/Form/Fields/FieldCheckbox/FieldCheckbox.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
import React, { forwardRef, Ref } from 'react'
2828
import styled from 'styled-components'
29-
import { v4 as uuid } from 'uuid'
29+
import { useID } from '../../../utils'
3030
import { useFormContext } from '../../Form'
3131
import { Checkbox, CheckboxProps } from '../../Inputs/Checkbox/Checkbox'
3232
import { omitFieldProps, pickFieldProps } from '../Field'
@@ -38,7 +38,7 @@ export interface FieldCheckboxProps extends CheckboxProps, FieldBaseProps {}
3838
const FieldCheckboxLayout = forwardRef(
3939
(props: FieldCheckboxProps, ref: Ref<HTMLInputElement>) => {
4040
const validationMessage = useFormContext(props)
41-
const { id = uuid() } = props
41+
const id = useID(props.id)
4242
return (
4343
<FieldInline
4444
{...pickFieldProps(props)}

packages/components/src/Form/Fields/FieldCheckbox/__snapshots__/FieldCheckbox.test.tsx.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ exports[`A FieldCheckbox 1`] = `
104104
color="palette.charcoal700"
105105
fontSize="xsmall"
106106
fontWeight="semiBold"
107+
htmlFor="FieldCheckboxID"
107108
>
108109
👍
109110
</span>
@@ -254,6 +255,7 @@ exports[`A FieldCheckbox with checked value 1`] = `
254255
color="palette.charcoal700"
255256
fontSize="xsmall"
256257
fontWeight="semiBold"
258+
htmlFor="FieldCheckboxID"
257259
>
258260
👍
259261
</span>

packages/components/src/Form/Fields/FieldCheckboxGroup/FieldCheckboxGroup.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
import React, { FC } from 'react'
2828
import styled from 'styled-components'
29-
import { v4 as uuid } from 'uuid'
29+
import { useID } from '../../../utils'
3030
import { useFormContext } from '../../Form'
3131
import { CheckboxGroup, CheckboxGroupProps } from '../../Inputs'
3232
import { Field, FieldProps, omitFieldProps, pickFieldProps } from '../Field'
@@ -36,12 +36,13 @@ export interface FieldCheckboxGroupProps
3636
Omit<FieldProps, 'detail'> {}
3737

3838
const FieldCheckboxGroupLayout: FC<FieldCheckboxGroupProps> = ({
39-
id = uuid(),
39+
id: propsID,
4040
options,
4141
value,
4242
...props
4343
}) => {
4444
const validationMessage = useFormContext(props)
45+
const id = useID(propsID)
4546

4647
return (
4748
<Field

packages/components/src/Form/Fields/FieldInline.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ const FieldInlineLayout: FC<Omit<
5555
}) => {
5656
return (
5757
<label className={className}>
58-
<Label as="span" fontSize={labelFontSize}>
58+
<Label as="span" fontSize={labelFontSize} htmlFor={id}>
5959
{label}
6060
{required && <RequiredStar />}
6161
</Label>

packages/components/src/Form/Fields/FieldRadio/FieldRadio.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
import React, { forwardRef, Ref } from 'react'
2828
import styled from 'styled-components'
29-
import { v4 as uuid } from 'uuid'
29+
import { useID } from '../../../utils'
3030
import { Radio, RadioProps } from '../../Inputs/Radio/Radio'
3131
import { omitFieldProps, pickFieldProps } from '../Field'
3232
import { FieldInline } from '../FieldInline'
@@ -38,7 +38,7 @@ export interface FieldRadioProps
3838

3939
const FieldRadioLayout = forwardRef(
4040
(props: FieldRadioProps, ref: Ref<HTMLInputElement>) => {
41-
const { id = uuid() } = props
41+
const id = useID(props.id)
4242
return (
4343
<FieldInline {...pickFieldProps(props)} id={id}>
4444
<Radio

packages/components/src/Form/Fields/FieldRadio/__snapshots__/FieldRadio.test.tsx.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ exports[`A FieldRadio 1`] = `
109109
color="palette.charcoal700"
110110
fontSize="xsmall"
111111
fontWeight="semiBold"
112+
htmlFor="FieldRadioID"
112113
>
113114
👍
114115
</span>
@@ -245,6 +246,7 @@ exports[`A FieldRadio checked 1`] = `
245246
color="palette.charcoal700"
246247
fontSize="xsmall"
247248
fontWeight="semiBold"
249+
htmlFor="FieldRadioID"
248250
>
249251
👍
250252
</span>

packages/components/src/Form/Fields/FieldRadioGroup/FieldRadioGroup.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
import React, { FC } from 'react'
2828
import styled from 'styled-components'
29-
import { v4 as uuid } from 'uuid'
29+
import { useID } from '../../../utils'
3030
import { useFormContext } from '../../Form'
3131
import { Field, FieldProps, omitFieldProps, pickFieldProps } from '../Field'
3232
import { RadioGroup, RadioGroupProps } from '../../Inputs/OptionsGroup'
@@ -36,11 +36,12 @@ export interface FieldRadioGroupProps
3636
Omit<FieldProps, 'detail'> {}
3737

3838
const FieldRadioGroupLayout: FC<FieldRadioGroupProps> = ({
39-
id = uuid(),
39+
id: propsID,
4040
options,
4141
...props
4242
}) => {
4343
const validationMessage = useFormContext(props)
44+
const id = useID(propsID)
4445

4546
return (
4647
<Field

packages/components/src/Form/Fields/FieldSelect/FieldSelect.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
import React, { forwardRef, Ref } from 'react'
2828
import styled from 'styled-components'
29-
import { v4 as uuid } from 'uuid'
29+
import { useID } from '../../../utils'
3030
import { useFormContext } from '../../Form'
3131
import { Select, SelectProps } from '../../Inputs/Select/Select'
3232
import { Field, FieldProps, omitFieldProps, pickFieldProps } from '../Field'
@@ -36,7 +36,7 @@ export interface FieldSelectProps extends FieldProps, SelectProps {}
3636
const FieldSelectComponent = forwardRef(
3737
(props: FieldSelectProps, ref: Ref<HTMLInputElement>) => {
3838
const validationMessage = useFormContext(props)
39-
const { id = uuid() } = props
39+
const id = useID(props.id)
4040
return (
4141
<Field
4242
{...pickFieldProps(props)}

0 commit comments

Comments
 (0)