@oslokommune/punkt-react 18.7.2 → 18.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +22 -0
- package/dist/punkt-react.cjs +1 -1
- package/dist/punkt-react.js +394 -396
- package/package.json +3 -3
- package/src/components/checkbox/Checkbox.tsx +26 -13
- package/src/components/radio/RadioButton.tsx +22 -19
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oslokommune/punkt-react",
|
|
3
|
-
"version": "18.
|
|
3
|
+
"version": "18.8.0",
|
|
4
4
|
"description": "React komponentbibliotek til Punkt, et designsystem laget av Oslo Origo",
|
|
5
5
|
"homepage": "https://punkt.oslo.kommune.no",
|
|
6
6
|
"author": "Team Designsystem, Oslo Origo",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"@eslint/eslintrc": "^3.3.5",
|
|
41
41
|
"@eslint/js": "^10.0.1",
|
|
42
42
|
"@oslokommune/punkt-assets": "^18.7.1",
|
|
43
|
-
"@oslokommune/punkt-css": "^18.
|
|
43
|
+
"@oslokommune/punkt-css": "^18.8.0",
|
|
44
44
|
"@testing-library/jest-dom": "^6.9.1",
|
|
45
45
|
"@testing-library/react": "^16.3.2",
|
|
46
46
|
"@testing-library/user-event": "^14.6.1",
|
|
@@ -100,5 +100,5 @@
|
|
|
100
100
|
"url": "https://github.com/oslokommune/punkt/issues"
|
|
101
101
|
},
|
|
102
102
|
"license": "MIT",
|
|
103
|
-
"gitHead": "
|
|
103
|
+
"gitHead": "30be2be7365f440b93da5bad8ca3e883255d647a"
|
|
104
104
|
}
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
useRef,
|
|
10
10
|
} from 'react'
|
|
11
11
|
import { usePktStrings } from '../../hooks/usePktStrings'
|
|
12
|
+
import { useGeneratedId } from '../../hooks/useGeneratedId'
|
|
12
13
|
import type { IPktStringsProps } from 'shared-strings'
|
|
13
14
|
|
|
14
15
|
export interface IPktCheckbox extends InputHTMLAttributes<HTMLInputElement>, IPktStringsProps<'forms'> {
|
|
@@ -38,7 +39,7 @@ export interface IPktCheckbox extends InputHTMLAttributes<HTMLInputElement>, IPk
|
|
|
38
39
|
export const PktCheckbox = forwardRef(
|
|
39
40
|
(
|
|
40
41
|
{
|
|
41
|
-
id,
|
|
42
|
+
id: idProp,
|
|
42
43
|
hasTile = false,
|
|
43
44
|
disabled = false,
|
|
44
45
|
label,
|
|
@@ -57,11 +58,13 @@ export const PktCheckbox = forwardRef(
|
|
|
57
58
|
requiredText,
|
|
58
59
|
strings,
|
|
59
60
|
tagText,
|
|
61
|
+
'aria-describedby': ariaDescribedbyProp,
|
|
60
62
|
...props
|
|
61
63
|
}: IPktCheckbox,
|
|
62
64
|
ref: ForwardedRef<HTMLInputElement>,
|
|
63
65
|
): ReactElement => {
|
|
64
66
|
const s = usePktStrings(['forms'], strings)
|
|
67
|
+
const id = useGeneratedId(idProp)
|
|
65
68
|
const internalRef = useRef<HTMLInputElement>(null)
|
|
66
69
|
|
|
67
70
|
useEffect(() => {
|
|
@@ -112,15 +115,28 @@ export const PktCheckbox = forwardRef(
|
|
|
112
115
|
)
|
|
113
116
|
}
|
|
114
117
|
|
|
118
|
+
const labelId = `${id}-check-label`
|
|
119
|
+
const helptextId = `${id}-check-helptext`
|
|
120
|
+
const describedBy =
|
|
121
|
+
[checkHelptext ? helptextId : undefined, ariaDescribedbyProp].filter(Boolean).join(' ') || undefined
|
|
122
|
+
|
|
123
|
+
const renderLabel = () => (
|
|
124
|
+
<label className={labelClasses} htmlFor={id}>
|
|
125
|
+
<span id={labelId}>
|
|
126
|
+
{label} {renderTags()}
|
|
127
|
+
</span>
|
|
128
|
+
{checkHelptext && (
|
|
129
|
+
<div id={helptextId} className="pkt-input-check__input-helptext">
|
|
130
|
+
{checkHelptext}
|
|
131
|
+
</div>
|
|
132
|
+
)}
|
|
133
|
+
</label>
|
|
134
|
+
)
|
|
135
|
+
|
|
115
136
|
return (
|
|
116
137
|
<div className={classes}>
|
|
117
138
|
<div className={inputTileClasses}>
|
|
118
|
-
{labelPosition === 'left' && (
|
|
119
|
-
<label className={labelClasses} htmlFor={id}>
|
|
120
|
-
{label} {renderTags()}
|
|
121
|
-
{checkHelptext && <div className="pkt-input-check__input-helptext">{checkHelptext}</div>}
|
|
122
|
-
</label>
|
|
123
|
-
)}
|
|
139
|
+
{labelPosition === 'left' && renderLabel()}
|
|
124
140
|
<input
|
|
125
141
|
role={isSwitch ? 'switch' : 'checkbox'}
|
|
126
142
|
ref={internalRef}
|
|
@@ -128,15 +144,12 @@ export const PktCheckbox = forwardRef(
|
|
|
128
144
|
type="checkbox"
|
|
129
145
|
id={id}
|
|
130
146
|
disabled={disabled}
|
|
147
|
+
aria-labelledby={label ? labelId : undefined}
|
|
148
|
+
aria-describedby={describedBy}
|
|
131
149
|
{...(checked !== undefined ? { checked } : { defaultChecked })}
|
|
132
150
|
{...props}
|
|
133
151
|
/>
|
|
134
|
-
{labelPosition === 'right' && (
|
|
135
|
-
<label className={labelClasses} htmlFor={id}>
|
|
136
|
-
{label} {renderTags()}
|
|
137
|
-
{checkHelptext && <div className="pkt-input-check__input-helptext">{checkHelptext}</div>}
|
|
138
|
-
</label>
|
|
139
|
-
)}
|
|
152
|
+
{labelPosition === 'right' && renderLabel()}
|
|
140
153
|
</div>
|
|
141
154
|
</div>
|
|
142
155
|
)
|
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ChangeEventHandler,
|
|
3
|
-
ForwardedRef,
|
|
4
|
-
forwardRef,
|
|
5
|
-
type InputHTMLAttributes,
|
|
6
|
-
ReactElement,
|
|
7
|
-
ReactNode,
|
|
8
|
-
} from 'react'
|
|
1
|
+
import { ChangeEventHandler, ForwardedRef, forwardRef, type InputHTMLAttributes, ReactElement, ReactNode } from 'react'
|
|
9
2
|
import { usePktStrings } from '../../hooks/usePktStrings'
|
|
3
|
+
import { useGeneratedId } from '../../hooks/useGeneratedId'
|
|
10
4
|
import type { IPktStringsProps } from 'shared-strings'
|
|
11
5
|
|
|
12
6
|
export interface IPktRadioButton extends InputHTMLAttributes<HTMLInputElement>, IPktStringsProps<'forms'> {
|
|
@@ -33,7 +27,7 @@ export interface IPktRadioButton extends InputHTMLAttributes<HTMLInputElement>,
|
|
|
33
27
|
export const PktRadioButton = forwardRef(
|
|
34
28
|
(
|
|
35
29
|
{
|
|
36
|
-
id,
|
|
30
|
+
id: idProp,
|
|
37
31
|
name,
|
|
38
32
|
label,
|
|
39
33
|
className,
|
|
@@ -49,11 +43,13 @@ export const PktRadioButton = forwardRef(
|
|
|
49
43
|
requiredText,
|
|
50
44
|
strings,
|
|
51
45
|
tagText,
|
|
46
|
+
'aria-describedby': ariaDescribedbyProp,
|
|
52
47
|
...props
|
|
53
48
|
}: IPktRadioButton,
|
|
54
49
|
ref: ForwardedRef<HTMLInputElement>,
|
|
55
50
|
): ReactElement => {
|
|
56
51
|
const s = usePktStrings(['forms'], strings)
|
|
52
|
+
const id = useGeneratedId(idProp)
|
|
57
53
|
const classes = [className, 'pkt-input-check'].filter(Boolean).join(' ')
|
|
58
54
|
|
|
59
55
|
const inputTileClasses = [
|
|
@@ -82,19 +78,18 @@ export const PktRadioButton = forwardRef(
|
|
|
82
78
|
<>
|
|
83
79
|
{tagText && <span className={tagClasses + ` pkt-tag--gray`}>{tagText}</span>}
|
|
84
80
|
{optionalTag && (
|
|
85
|
-
<span className={tagClasses + ` pkt-tag--blue-light`}>
|
|
86
|
-
{optionalText ?? s.forms.optional}
|
|
87
|
-
</span>
|
|
88
|
-
)}
|
|
89
|
-
{requiredTag && (
|
|
90
|
-
<span className={tagClasses + ` pkt-tag--beige`}>
|
|
91
|
-
{requiredText ?? s.forms.required}
|
|
92
|
-
</span>
|
|
81
|
+
<span className={tagClasses + ` pkt-tag--blue-light`}>{optionalText ?? s.forms.optional}</span>
|
|
93
82
|
)}
|
|
83
|
+
{requiredTag && <span className={tagClasses + ` pkt-tag--beige`}>{requiredText ?? s.forms.required}</span>}
|
|
94
84
|
</>
|
|
95
85
|
)
|
|
96
86
|
}
|
|
97
87
|
|
|
88
|
+
const labelId = `${id}-check-label`
|
|
89
|
+
const helptextId = `${id}-check-helptext`
|
|
90
|
+
const describedBy =
|
|
91
|
+
[checkHelptext ? helptextId : undefined, ariaDescribedbyProp].filter(Boolean).join(' ') || undefined
|
|
92
|
+
|
|
98
93
|
return (
|
|
99
94
|
<div className={classes}>
|
|
100
95
|
<div className={inputTileClasses}>
|
|
@@ -105,12 +100,20 @@ export const PktRadioButton = forwardRef(
|
|
|
105
100
|
name={name}
|
|
106
101
|
disabled={disabled}
|
|
107
102
|
className={inputCheckBoxClasses}
|
|
103
|
+
aria-labelledby={label ? labelId : undefined}
|
|
104
|
+
aria-describedby={describedBy}
|
|
108
105
|
{...(checked !== undefined ? { checked } : { defaultChecked })}
|
|
109
106
|
{...props}
|
|
110
107
|
/>
|
|
111
108
|
<label className={labelClasses} htmlFor={id}>
|
|
112
|
-
|
|
113
|
-
|
|
109
|
+
<span id={labelId}>
|
|
110
|
+
{label} {renderTags()}
|
|
111
|
+
</span>
|
|
112
|
+
{checkHelptext && (
|
|
113
|
+
<div id={helptextId} className="pkt-input-check__input-helptext">
|
|
114
|
+
{checkHelptext}
|
|
115
|
+
</div>
|
|
116
|
+
)}
|
|
114
117
|
</label>
|
|
115
118
|
</div>
|
|
116
119
|
</div>
|