Skip to content

Commit c219d87

Browse files
committed
refactor(field): rename labelElementID prop to labelID for naming consistency
1 parent bfcbf64 commit c219d87

7 files changed

Lines changed: 27 additions & 21 deletions

File tree

.changeset/field-labelid-naming.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@astryxdesign/core': patch
3+
---
4+
5+
[refactor] Rename the Field `labelElementID` prop to `labelID`, matching the `(part)ID` naming convention used by the sibling props (`inputID`, `descriptionID`, `messageID`). The disambiguation between "the id applied to the label element" and `inputID` ("the control the label points at") now lives in the prop JSDoc rather than the name. Also renamed on FieldLabel and updated the RadioList/CheckboxList/InputGroup consumers. No behavior change. (#3343)
6+
@cixzhang

packages/core/src/CheckboxList/CheckboxList.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ export function CheckboxList({
151151
'data-testid': dataTestId,
152152
}: CheckboxListProps) {
153153
const inputID = useId();
154-
const labelElementID = useId();
154+
const labelID = useId();
155155
const descriptionID = useId();
156156
const statusMessageID = useId();
157157

@@ -211,7 +211,7 @@ export function CheckboxList({
211211
isLabelHidden={isLabelHidden}
212212
description={description}
213213
inputID={inputID}
214-
labelElementID={labelElementID}
214+
labelID={labelID}
215215
isGroupLabel
216216
descriptionID={description ? descriptionID : undefined}
217217
isDisabled={isDisabled}
@@ -231,7 +231,7 @@ export function CheckboxList({
231231
<CheckboxListContext value={contextValue}>
232232
<div
233233
role="group"
234-
aria-labelledby={labelElementID}
234+
aria-labelledby={labelID}
235235
aria-describedby={
236236
[
237237
description ? descriptionID : null,

packages/core/src/Field/Field.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ describe('Field', () => {
109109
<Field
110110
label="Plan"
111111
inputID="plan-group"
112-
labelElementID="plan-label"
112+
labelID="plan-label"
113113
isGroupLabel>
114114
<div role="radiogroup" aria-labelledby="plan-label" />
115115
</Field>,
@@ -119,7 +119,7 @@ describe('Field', () => {
119119
expect(labelEl.tagName).toBe('SPAN');
120120
expect(labelEl.closest('label')).toBeNull();
121121
expect(labelEl).not.toHaveAttribute('for');
122-
// labelElementID is applied to the label element and referenced by the group.
122+
// labelID is applied to the label element and referenced by the group.
123123
expect(labelEl).toHaveAttribute('id', 'plan-label');
124124
const group = screen.getByRole('radiogroup', {name: 'Plan'});
125125
expect(group.getAttribute('aria-labelledby')).toBe(labelEl.id);

packages/core/src/Field/Field.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export interface FieldProps extends Omit<
101101
/**
102102
* ID of the input element this label points AT (used as the label's
103103
* `htmlFor`). This is the id of the *control*, not of the label element —
104-
* see `labelElementID` for the latter.
104+
* see `labelID` for the latter.
105105
*/
106106
inputID: string;
107107
/**
@@ -110,12 +110,12 @@ export interface FieldProps extends Omit<
110110
* (radiogroup, checkbox group) references this via `aria-labelledby` to take
111111
* the label as its accessible name. Pair with `isGroupLabel`.
112112
*/
113-
labelElementID?: string;
113+
labelID?: string;
114114
/**
115115
* When the field wraps a group of controls rather than a single input, set
116116
* this so the label renders as a non-`<label>` element (a `<span>`): a
117117
* `<label>` semantically names one control and can't be associated with a
118-
* group. Pair with `labelElementID` + `aria-labelledby` on the group.
118+
* group. Pair with `labelID` + `aria-labelledby` on the group.
119119
* @default false
120120
*/
121121
isGroupLabel?: boolean;
@@ -189,7 +189,7 @@ export function Field({
189189
isLabelHidden = false,
190190
description,
191191
inputID,
192-
labelElementID,
192+
labelID,
193193
isGroupLabel = false,
194194
descriptionID,
195195
isOptional = false,
@@ -225,7 +225,7 @@ export function Field({
225225
<FieldLabel
226226
label={label}
227227
inputID={inputID}
228-
labelElementID={labelElementID}
228+
labelID={labelID}
229229
isGroupLabel={isGroupLabel}
230230
isLabelHidden={isLabelHidden}
231231
isDisabled={isDisabled}

packages/core/src/Field/FieldLabel.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export interface FieldLabelProps extends BaseProps<HTMLLabelElement> {
8484
/**
8585
* ID of the input element this label points AT (rendered as `htmlFor` on the
8686
* label). This is *not* the id of the label element itself — see
87-
* `labelElementID` for that.
87+
* `labelID` for that.
8888
*/
8989
inputID: string;
9090
/**
@@ -93,14 +93,14 @@ export interface FieldLabelProps extends BaseProps<HTMLLabelElement> {
9393
* reference this via `aria-labelledby` to take the label as its accessible
9494
* name.
9595
*/
96-
labelElementID?: string;
96+
labelID?: string;
9797
/**
9898
* When true, the field wraps a *group* of controls (e.g. a radiogroup)
9999
* rather than a single input. In that case the label is rendered as a
100100
* `<span>` instead of a `<label>` — a `<label>` semantically names one form
101101
* control and can't be associated with a group, so it must not be a literal
102102
* label element. The group takes the label as its name via
103-
* `labelElementID` + `aria-labelledby`.
103+
* `labelID` + `aria-labelledby`.
104104
* @default false
105105
*/
106106
isGroupLabel?: boolean;
@@ -161,7 +161,7 @@ export interface FieldLabelProps extends BaseProps<HTMLLabelElement> {
161161
export function FieldLabel({
162162
label,
163163
inputID,
164-
labelElementID,
164+
labelID,
165165
isGroupLabel = false,
166166
isLabelHidden = false,
167167
isDisabled = false,
@@ -203,7 +203,7 @@ export function FieldLabel({
203203
<>
204204
<LabelElement
205205
ref={ref}
206-
id={labelElementID}
206+
id={labelID}
207207
// `htmlFor` only applies to a real `<label>` associating with a single
208208
// control; a group label (span) has no `htmlFor`.
209209
htmlFor={isGroupLabel ? undefined : inputID}

packages/core/src/InputGroup/InputGroup.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ export function InputGroup({
156156
}: InputGroupProps) {
157157
const size = useSize(sizeProp, 'md');
158158
const inputId = useId();
159-
const labelElementId = useId();
159+
const labelID = useId();
160160
const statusMessageId = useId();
161161

162162
const contextValue = useMemo(() => ({isInGroup: true as const}), []);
@@ -169,7 +169,7 @@ export function InputGroup({
169169
isLabelHidden={isLabelHidden}
170170
description={description}
171171
inputID={inputId}
172-
labelElementID={labelElementId}
172+
labelID={labelID}
173173
isGroupLabel
174174
isOptional={isOptional}
175175
isRequired={isRequired}
@@ -188,7 +188,7 @@ export function InputGroup({
188188
<div
189189
ref={ref}
190190
role="group"
191-
aria-labelledby={labelElementId}
191+
aria-labelledby={labelID}
192192
data-testid={testId}
193193
{...rest}
194194
{...mergeProps(

packages/core/src/RadioList/RadioList.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ export function RadioList({
183183
}: RadioListProps) {
184184
const name = useId();
185185
const inputID = useId();
186-
const labelElementID = useId();
186+
const labelID = useId();
187187
const descriptionID = useId();
188188
const statusMessageID = useId();
189189

@@ -284,7 +284,7 @@ export function RadioList({
284284
isLabelHidden={isLabelHidden}
285285
description={description}
286286
inputID={inputID}
287-
labelElementID={labelElementID}
287+
labelID={labelID}
288288
isGroupLabel
289289
descriptionID={description ? descriptionID : undefined}
290290
isOptional={isOptional}
@@ -308,7 +308,7 @@ export function RadioList({
308308
<div
309309
ref={groupRef}
310310
role="radiogroup"
311-
aria-labelledby={labelElementID}
311+
aria-labelledby={labelID}
312312
onFocus={handleFocus}
313313
aria-describedby={
314314
[

0 commit comments

Comments
 (0)