@oslokommune/punkt-react 19.5.0 → 19.5.2
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 +8 -0
- package/dist/components/inputwrapper/InputWrapper.test.d.ts +0 -0
- package/dist/punkt-react.cjs +1 -1
- package/dist/punkt-react.js +6 -2
- package/package.json +2 -2
- package/src/components/combobox/Combobox.core.test.tsx +6 -3
- package/src/components/inputwrapper/InputWrapper.test.tsx +57 -0
- package/src/components/inputwrapper/InputWrapper.tsx +17 -1
package/dist/punkt-react.js
CHANGED
|
@@ -3187,7 +3187,7 @@ sr.displayName = "PktHelptext";
|
|
|
3187
3187
|
//#endregion
|
|
3188
3188
|
//#region src/components/inputwrapper/InputWrapper.tsx
|
|
3189
3189
|
var cr = i(({ forId: e, label: t, helptext: n, helptextDropdown: r, helptextDropdownButton: i, counter: a, counterCurrent: o = 0, counterMaxLength: s, optionalTag: c = !1, optionalText: l, requiredTag: u = !1, requiredText: d, tagText: p = null, hasError: m = !1, errorMessage: h, disabled: y = !1, inline: b = !1, ariaDescribedby: x, useWrapper: S = !0, children: C, className: w = "", hasFieldset: T = !1, role: E, counterPosition: D = "bottom", size: O = "medium", strings: k }, A) => {
|
|
3190
|
-
let j = tr(A), M = Ce(["forms", "validation"], k), N = f(() => Qn(), []), P = e || N, F = x || (n ? `${P}-helptext` : void 0
|
|
3190
|
+
let j = tr(A), M = Ce(["forms", "validation"], k), N = f(() => Qn(), []), P = e || N, F = [...new Set([x || (n ? `${P}-helptext` : ""), m && h ? `${P}-error` : ""].join(" ").split(" ").filter(Boolean))].join(" ") || void 0, ee = !!a, te = ee && D === "top", I = ee && D === "bottom", ne = [
|
|
3191
3191
|
"pkt-inputwrapper",
|
|
3192
3192
|
w,
|
|
3193
3193
|
m ? "pkt-inputwrapper--error" : "",
|
|
@@ -3229,7 +3229,11 @@ var cr = i(({ forId: e, label: t, helptext: n, helptextDropdown: r, helptextDrop
|
|
|
3229
3229
|
" ",
|
|
3230
3230
|
ae()
|
|
3231
3231
|
] });
|
|
3232
|
-
return S
|
|
3232
|
+
return !S && T ? /* @__PURE__ */ _("legend", {
|
|
3233
|
+
className: "pkt-sr-only",
|
|
3234
|
+
id: `${P}-label`,
|
|
3235
|
+
children: t
|
|
3236
|
+
}) : S ? T ? /* @__PURE__ */ _("legend", {
|
|
3233
3237
|
className: "pkt-inputwrapper__legend",
|
|
3234
3238
|
id: `${P}-label`,
|
|
3235
3239
|
children: e
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oslokommune/punkt-react",
|
|
3
|
-
"version": "19.5.
|
|
3
|
+
"version": "19.5.2",
|
|
4
4
|
"description": "React komponentbibliotek til Punkt, designsystem for Oslo kommune",
|
|
5
5
|
"homepage": "https://punkt.oslo.kommune.no",
|
|
6
6
|
"author": "Team Designsystem, Oslo kommune",
|
|
@@ -101,5 +101,5 @@
|
|
|
101
101
|
"url": "https://github.com/oslokommune/punkt/issues"
|
|
102
102
|
},
|
|
103
103
|
"license": "MIT",
|
|
104
|
-
"gitHead": "
|
|
104
|
+
"gitHead": "519d9c748c2bef3bdb12d5979e115c05a2509f44"
|
|
105
105
|
}
|
|
@@ -475,9 +475,12 @@ describe('PktCombobox', () => {
|
|
|
475
475
|
test('renders label as screen-reader-only when useWrapper is false', () => {
|
|
476
476
|
const { container } = createComboboxTest({ useWrapper: false })
|
|
477
477
|
|
|
478
|
-
const
|
|
479
|
-
expect(
|
|
480
|
-
expect(
|
|
478
|
+
const legend = container.querySelector('fieldset > legend')
|
|
479
|
+
expect(legend).toBeInTheDocument()
|
|
480
|
+
expect(legend).toHaveClass('pkt-sr-only')
|
|
481
|
+
|
|
482
|
+
const combobox = container.querySelector('[role="combobox"]')
|
|
483
|
+
expect(combobox?.getAttribute('aria-labelledby')).toBe(legend?.id)
|
|
481
484
|
})
|
|
482
485
|
})
|
|
483
486
|
})
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import '@testing-library/jest-dom'
|
|
2
|
+
|
|
3
|
+
import { render } from '@testing-library/react'
|
|
4
|
+
|
|
5
|
+
import { PktInputWrapper } from './InputWrapper'
|
|
6
|
+
|
|
7
|
+
const renderFieldset = (props: Partial<Parameters<typeof PktInputWrapper>[0]> = {}) => {
|
|
8
|
+
const { container } = render(
|
|
9
|
+
<PktInputWrapper forId="g" label="Gruppe" hasFieldset {...props}>
|
|
10
|
+
<input type="radio" name="g" aria-label="Valg" />
|
|
11
|
+
</PktInputWrapper>,
|
|
12
|
+
)
|
|
13
|
+
return container.querySelector('fieldset') as HTMLFieldSetElement
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const describedByIds = (fieldset: HTMLFieldSetElement) =>
|
|
17
|
+
(fieldset.getAttribute('aria-describedby') ?? '').split(' ').filter(Boolean)
|
|
18
|
+
|
|
19
|
+
describe('PktInputWrapper', () => {
|
|
20
|
+
describe('fieldset name and description', () => {
|
|
21
|
+
test('links the error message to the fieldset', () => {
|
|
22
|
+
const fieldset = renderFieldset({ hasError: true, errorMessage: 'Velg ett alternativ' })
|
|
23
|
+
|
|
24
|
+
expect(describedByIds(fieldset)).toContain('g-error')
|
|
25
|
+
expect(document.getElementById('g-error')).toBeInTheDocument()
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
test('links both helptext and error message to the fieldset', () => {
|
|
29
|
+
const fieldset = renderFieldset({ helptext: 'Velg ett', hasError: true, errorMessage: 'Mangler' })
|
|
30
|
+
|
|
31
|
+
expect(describedByIds(fieldset)).toEqual(['g-helptext', 'g-error'])
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
test('does not link an error message when hasError is off', () => {
|
|
35
|
+
const fieldset = renderFieldset({ errorMessage: 'Mangler' })
|
|
36
|
+
|
|
37
|
+
expect(fieldset).not.toHaveAttribute('aria-describedby')
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
test('only references ids that are rendered', () => {
|
|
41
|
+
const fieldset = renderFieldset({ helptext: 'Velg ett', hasError: true, errorMessage: 'Mangler' })
|
|
42
|
+
|
|
43
|
+
describedByIds(fieldset).forEach((id) => {
|
|
44
|
+
expect(document.getElementById(id)).toBeInTheDocument()
|
|
45
|
+
})
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
test('names the fieldset with a hidden legend when useWrapper is off', () => {
|
|
49
|
+
const fieldset = renderFieldset({ useWrapper: false })
|
|
50
|
+
|
|
51
|
+
const legend = fieldset.querySelector(':scope > legend')
|
|
52
|
+
expect(legend).toHaveClass('pkt-sr-only')
|
|
53
|
+
expect(legend?.textContent?.trim()).toBe('Gruppe')
|
|
54
|
+
expect(fieldset.querySelector('label')).toBeNull()
|
|
55
|
+
})
|
|
56
|
+
})
|
|
57
|
+
})
|
|
@@ -79,7 +79,15 @@ export const PktInputWrapper = forwardRef(
|
|
|
79
79
|
const generatedId = useMemo(() => uuidish(), [])
|
|
80
80
|
const forId = forIdProp || generatedId
|
|
81
81
|
|
|
82
|
-
const describedBy =
|
|
82
|
+
const describedBy =
|
|
83
|
+
[
|
|
84
|
+
...new Set(
|
|
85
|
+
[ariaDescribedby || (helptext ? `${forId}-helptext` : ''), hasError && errorMessage ? `${forId}-error` : '']
|
|
86
|
+
.join(' ')
|
|
87
|
+
.split(' ')
|
|
88
|
+
.filter(Boolean),
|
|
89
|
+
),
|
|
90
|
+
].join(' ') || undefined
|
|
83
91
|
const showCounter = !!counter
|
|
84
92
|
const counterTop = showCounter && counterPosition === 'top'
|
|
85
93
|
const counterBottom = showCounter && counterPosition === 'bottom'
|
|
@@ -133,6 +141,14 @@ export const PktInputWrapper = forwardRef(
|
|
|
133
141
|
</>
|
|
134
142
|
)
|
|
135
143
|
|
|
144
|
+
if (!useWrapper && hasFieldset) {
|
|
145
|
+
return (
|
|
146
|
+
<legend className="pkt-sr-only" id={`${forId}-label`}>
|
|
147
|
+
{label}
|
|
148
|
+
</legend>
|
|
149
|
+
)
|
|
150
|
+
}
|
|
151
|
+
|
|
136
152
|
if (!useWrapper) {
|
|
137
153
|
return (
|
|
138
154
|
<label htmlFor={forId} className="pkt-sr-only" id={`${forId}-label`}>
|