Skip to content

Commit 8586817

Browse files
Update data attributes to use string values
1 parent f98d12a commit 8586817

File tree

4 files changed

+11
-17
lines changed

4 files changed

+11
-17
lines changed

src/components/form-elements/character-count/CharacterCount.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ export const CharacterCount = forwardRef<HTMLTextAreaElement, CharacterCountProp
4141
...formGroupProps,
4242
'className': classNames('nhsuk-character-count', formGroupProps?.className),
4343
'data-module': 'nhsuk-character-count',
44-
'data-maxlength': maxLength,
45-
'data-maxwords': maxWords,
46-
'data-threshold': threshold,
44+
'data-maxlength': maxLength?.toString(),
45+
'data-maxwords': maxWords?.toString(),
46+
'data-threshold': threshold?.toString(),
4747
'ref': moduleRef,
4848
}}
4949
{...rest}

src/components/form-elements/checkboxes/components/CheckboxesItem.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
import { CheckboxesContext, type ICheckboxesContext } from '../CheckboxesContext.js';
1414
import { HintText } from '#components/form-elements/hint-text/index.js';
1515
import { Label } from '#components/form-elements/label/index.js';
16-
import { type FormElementProps, type HTMLAttributesWithData } from '#util/types/index.js';
16+
import { type ComponentPropsWithDataAttributes, type FormElementProps } from '#util/types/index.js';
1717

1818
export interface CheckboxesItemProps
1919
extends ComponentPropsWithoutRef<'input'>,
@@ -54,10 +54,10 @@ export const CheckboxesItem = forwardRef<HTMLInputElement, CheckboxesItemProps>(
5454

5555
useEffect(() => () => unleaseReference(checkboxReference));
5656

57-
const inputProps: HTMLAttributesWithData<HTMLInputElement> = rest;
57+
const inputProps: ComponentPropsWithDataAttributes<'input'> = rest;
5858

5959
if (exclusive) {
60-
inputProps['data-checkbox-exclusive'] = true;
60+
inputProps['data-checkbox-exclusive'] = 'true';
6161
}
6262

6363
return (

src/util/types/FormTypes.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import { type ComponentPropsWithRef } from 'react';
2-
31
import { type ErrorMessageProps } from '#components/form-elements/error-message/index.js';
42
import { type FieldsetProps } from '#components/form-elements/fieldset/index.js';
53
import { type HintTextProps } from '#components/form-elements/hint-text/index.js';
64
import { type LabelProps } from '#components/form-elements/label/index.js';
75
import { type LegendProps } from '#components/form-elements/legend/index.js';
6+
import { type ComponentPropsWithDataAttributes } from '#util/types/index.js';
87

98
export interface FormElementProps {
109
'fieldsetProps'?: FieldsetProps;
@@ -16,12 +15,7 @@ export interface FormElementProps {
1615
'errorProps'?: ErrorMessageProps;
1716
'hint'?: string;
1817
'hintProps'?: HintTextProps;
19-
'formGroupProps'?: ComponentPropsWithRef<'div'> & {
20-
'data-module'?: string;
21-
'data-maxlength'?: number;
22-
'data-maxwords'?: number;
23-
'data-threshold'?: number;
24-
};
18+
'formGroupProps'?: ComponentPropsWithDataAttributes<'div'>;
2519
'id'?: string;
2620
'name'?: string;
2721
'aria-describedby'?: string;

src/util/types/NHSUKTypes.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type HTMLAttributes } from 'react';
1+
import { type ComponentProps, type ElementType } from 'react';
22

33
export type NHSUKSize = 's' | 'm' | 'l' | 'xl';
44

@@ -16,6 +16,6 @@ export type ColWidth =
1616
| 'one-third'
1717
| 'one-quarter';
1818

19-
export type HTMLAttributesWithData<T> = HTMLAttributes<T> & {
20-
[key: `data-${string}`]: unknown;
19+
export type ComponentPropsWithDataAttributes<T extends ElementType> = ComponentProps<T> & {
20+
[key: `data-${string}`]: string | undefined;
2121
};

0 commit comments

Comments
 (0)