@oslokommune/punkt-react 18.9.4 → 18.9.6
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 +18 -0
- package/dist/components/combobox/types.d.ts +2 -0
- package/dist/components/helptext/helptextAssociation.test.d.ts +1 -0
- package/dist/punkt-react.cjs +1 -1
- package/dist/punkt-react.js +827 -817
- package/package.json +3 -3
- package/src/components/combobox/ComboboxInput.tsx +9 -0
- package/src/components/combobox/types.ts +2 -0
- package/src/components/combobox/useComboboxState.ts +2 -0
- package/src/components/fileupload/FileUpload.tsx +22 -26
- package/src/components/helptext/helptextAssociation.test.tsx +100 -0
- package/src/components/timepicker/Timepicker.tsx +8 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oslokommune/punkt-react",
|
|
3
|
-
"version": "18.9.
|
|
3
|
+
"version": "18.9.6",
|
|
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",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"@eslint/eslintrc": "^3.3.5",
|
|
41
41
|
"@eslint/js": "^10.0.1",
|
|
42
42
|
"@oslokommune/punkt-assets": "^18.9.1",
|
|
43
|
-
"@oslokommune/punkt-css": "^18.9.
|
|
43
|
+
"@oslokommune/punkt-css": "^18.9.6",
|
|
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": "7f633a3524d23983b7fb3ab42a35150de6788f37"
|
|
104
104
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
|
|
3
3
|
import { findOptionByValue, findOptionIndex } from 'shared-utils/combobox'
|
|
4
|
+
import { describedByIds } from 'shared-utils/forms/described-by'
|
|
4
5
|
import { PktIcon } from '../icon/Icon'
|
|
5
6
|
import { ComboboxTags, SingleValueDisplay } from './ComboboxTags'
|
|
6
7
|
import type { IComboboxState } from './types'
|
|
@@ -72,10 +73,17 @@ export const ComboboxInput = ({ state }: IComboboxInputProps) => {
|
|
|
72
73
|
// Build selection description for screen readers
|
|
73
74
|
const selectionDescription = multiple && values.length > 0 ? `${values.length} valgt` : undefined
|
|
74
75
|
|
|
76
|
+
const describedBy = describedByIds({
|
|
77
|
+
id: hasTextInput ? inputId : `${id}-combobox`,
|
|
78
|
+
hasHelptext: !!state.helptext,
|
|
79
|
+
ariaDescribedby: state.ariaDescribedby,
|
|
80
|
+
})
|
|
81
|
+
|
|
75
82
|
// Select-only ARIA props (applied to the container div)
|
|
76
83
|
const selectOnlyProps = !hasTextInput
|
|
77
84
|
? {
|
|
78
85
|
id: `${id}-combobox`,
|
|
86
|
+
'aria-describedby': describedBy,
|
|
79
87
|
role: 'combobox' as const,
|
|
80
88
|
'aria-expanded': isOpen ? ('true' as const) : ('false' as const),
|
|
81
89
|
'aria-controls': listboxId,
|
|
@@ -134,6 +142,7 @@ export const ComboboxInput = ({ state }: IComboboxInputProps) => {
|
|
|
134
142
|
aria-controls={listboxId}
|
|
135
143
|
aria-activedescendant={activeDescendant}
|
|
136
144
|
aria-description={selectionDescription}
|
|
145
|
+
aria-describedby={describedBy}
|
|
137
146
|
disabled={disabled}
|
|
138
147
|
/>
|
|
139
148
|
</div>
|
|
@@ -34,6 +34,7 @@ export interface IPktCombobox extends IPktStringsProps<'combobox' | 'listbox' |
|
|
|
34
34
|
// Form
|
|
35
35
|
name?: string
|
|
36
36
|
form?: string
|
|
37
|
+
ariaDescribedby?: string
|
|
37
38
|
id?: string
|
|
38
39
|
disabled?: boolean
|
|
39
40
|
required?: boolean
|
|
@@ -124,6 +125,7 @@ export interface IComboboxState {
|
|
|
124
125
|
inputSize: 'small' | 'medium' | 'xsmall'
|
|
125
126
|
name?: string
|
|
126
127
|
form?: string
|
|
128
|
+
ariaDescribedby?: string
|
|
127
129
|
className?: string
|
|
128
130
|
|
|
129
131
|
// Derived state
|
|
@@ -82,6 +82,7 @@ export function useComboboxState(props: IPktCombobox, ref: React.ForwardedRef<HT
|
|
|
82
82
|
inputSize = 'medium',
|
|
83
83
|
name,
|
|
84
84
|
form,
|
|
85
|
+
ariaDescribedby,
|
|
85
86
|
className,
|
|
86
87
|
onChange,
|
|
87
88
|
onValueChange,
|
|
@@ -1155,6 +1156,7 @@ export function useComboboxState(props: IPktCombobox, ref: React.ForwardedRef<HT
|
|
|
1155
1156
|
inputSize,
|
|
1156
1157
|
name,
|
|
1157
1158
|
form,
|
|
1159
|
+
ariaDescribedby,
|
|
1158
1160
|
className,
|
|
1159
1161
|
|
|
1160
1162
|
// Derived
|
|
@@ -409,32 +409,28 @@ export const PktFileUpload: FC<IPktFileUpload> = forwardRef<HTMLInputElement, IP
|
|
|
409
409
|
</div>
|
|
410
410
|
)
|
|
411
411
|
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
<
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
)
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
return <div className="pkt-fileupload-component">{fileUploadContent}</div>
|
|
412
|
+
return (
|
|
413
|
+
<div className="pkt-fileupload-component">
|
|
414
|
+
<PktInputWrapper
|
|
415
|
+
strings={strings}
|
|
416
|
+
forId={id}
|
|
417
|
+
label={label ?? ''}
|
|
418
|
+
helptext={helptext}
|
|
419
|
+
helptextDropdown={helptextDropdown}
|
|
420
|
+
helptextDropdownButton={helptextDropdownButton}
|
|
421
|
+
disabled={disabled}
|
|
422
|
+
hasError={hasError}
|
|
423
|
+
optionalTag={optionalTag}
|
|
424
|
+
optionalText={optionalText}
|
|
425
|
+
requiredTag={requiredTag}
|
|
426
|
+
requiredText={requiredText}
|
|
427
|
+
tagText={tagText}
|
|
428
|
+
className={classNames('pkt-fileupload-wrapper', { 'pkt-fileupload-wrapper--full-width': fullwidth })}
|
|
429
|
+
>
|
|
430
|
+
{fileUploadContent}
|
|
431
|
+
</PktInputWrapper>
|
|
432
|
+
</div>
|
|
433
|
+
)
|
|
438
434
|
},
|
|
439
435
|
)
|
|
440
436
|
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { render } from '@testing-library/react'
|
|
2
|
+
import type { ReactNode } from 'react'
|
|
3
|
+
import { PktTextinput } from '../textinput/Textinput'
|
|
4
|
+
import { PktTextarea } from '../textarea/Textarea'
|
|
5
|
+
import { PktSelect } from '../select/Select'
|
|
6
|
+
import { PktCombobox } from '../combobox/Combobox'
|
|
7
|
+
import { PktDatepicker } from '../datepicker/Datepicker'
|
|
8
|
+
import { PktTimepicker } from '../timepicker/Timepicker'
|
|
9
|
+
import { PktFileUpload } from '../fileupload/FileUpload'
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The helptext must describe the control itself. `aria-describedby` on a label or
|
|
13
|
+
* on a wrapping element does not reach the field. See issue #3343.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
const H = 'Hjelpetekst'
|
|
17
|
+
const CONTROL = 'input:not([type="hidden"]):not([hidden]), textarea, select, [role="combobox"]'
|
|
18
|
+
|
|
19
|
+
const cases: Array<[string, () => ReactNode]> = [
|
|
20
|
+
['textinput', () => <PktTextinput id="felt" name="felt" label="Etikett" helptext={H} />],
|
|
21
|
+
['textarea', () => <PktTextarea id="felt" name="felt" label="Etikett" helptext={H} />],
|
|
22
|
+
[
|
|
23
|
+
'select',
|
|
24
|
+
() => (
|
|
25
|
+
<PktSelect id="felt" name="felt" label="Etikett" helptext={H}>
|
|
26
|
+
<option value="a">a</option>
|
|
27
|
+
</PktSelect>
|
|
28
|
+
),
|
|
29
|
+
],
|
|
30
|
+
['datepicker', () => <PktDatepicker id="felt" name="felt" label="Etikett" helptext={H} />],
|
|
31
|
+
['fileupload', () => <PktFileUpload id="felt" name="felt" label="Etikett" helptext={H} uploadStrategy="form" />],
|
|
32
|
+
['combobox', () => <PktCombobox id="felt" name="felt" label="Etikett" helptext={H} options={[]} />],
|
|
33
|
+
[
|
|
34
|
+
'combobox (allowUserInput)',
|
|
35
|
+
() => <PktCombobox id="felt" name="felt" label="Etikett" helptext={H} options={[]} allowUserInput />,
|
|
36
|
+
],
|
|
37
|
+
[
|
|
38
|
+
'combobox (typeahead)',
|
|
39
|
+
() => <PktCombobox id="felt" name="felt" label="Etikett" helptext={H} options={[]} typeahead />,
|
|
40
|
+
],
|
|
41
|
+
]
|
|
42
|
+
|
|
43
|
+
describe('helptext association', () => {
|
|
44
|
+
test.each(cases)('%s describes its control with the helptext', (_name, node) => {
|
|
45
|
+
const { container } = render(<div>{node()}</div>)
|
|
46
|
+
|
|
47
|
+
const helptext = container.querySelector('.pkt-inputwrapper__helptext')
|
|
48
|
+
expect(helptext?.id).toBeTruthy()
|
|
49
|
+
|
|
50
|
+
const control = container.querySelector(CONTROL)
|
|
51
|
+
expect(control).not.toBeNull()
|
|
52
|
+
expect(control?.getAttribute('aria-describedby')?.split(' ')).toContain(helptext?.id)
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
test('timepicker describes both spinbuttons with the helptext', () => {
|
|
56
|
+
const { container } = render(<PktTimepicker id="felt" name="felt" label="Etikett" helptext={H} />)
|
|
57
|
+
|
|
58
|
+
const helptext = container.querySelector('.pkt-inputwrapper__helptext')
|
|
59
|
+
expect(helptext?.id).toBeTruthy()
|
|
60
|
+
|
|
61
|
+
const spinbuttons = container.querySelectorAll('[role="spinbutton"]')
|
|
62
|
+
expect(spinbuttons).toHaveLength(2)
|
|
63
|
+
spinbuttons.forEach((spinbutton) => {
|
|
64
|
+
expect(spinbutton.getAttribute('aria-describedby')?.split(' ')).toContain(helptext?.id)
|
|
65
|
+
})
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
test('fileupload renders and links the helptext without a label', () => {
|
|
69
|
+
const { container } = render(<PktFileUpload id="felt" name="felt" helptext={H} uploadStrategy="form" />)
|
|
70
|
+
|
|
71
|
+
const helptext = container.querySelector('.pkt-inputwrapper__helptext')
|
|
72
|
+
expect(helptext?.textContent).toContain(H)
|
|
73
|
+
|
|
74
|
+
const input = container.querySelector('input[type="file"]')
|
|
75
|
+
expect(input?.getAttribute('aria-describedby')?.split(' ')).toContain(helptext?.id)
|
|
76
|
+
expect(input?.getAttribute('aria-label')).toBe('Velg fil')
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
test('combobox honours ariaDescribedby alongside the helptext', () => {
|
|
80
|
+
const { container } = render(
|
|
81
|
+
<>
|
|
82
|
+
<span id="ekstra">Ekstra beskrivelse</span>
|
|
83
|
+
<PktCombobox id="felt" name="felt" label="Etikett" helptext={H} options={[]} ariaDescribedby="ekstra" />
|
|
84
|
+
</>,
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
const describedBy = container.querySelector('[role="combobox"]')?.getAttribute('aria-describedby')?.split(' ')
|
|
88
|
+
|
|
89
|
+
expect(describedBy).toContain('felt-combobox-helptext')
|
|
90
|
+
expect(describedBy).toContain('ekstra')
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
test('no label carries the description', () => {
|
|
94
|
+
for (const [, node] of cases) {
|
|
95
|
+
const { container, unmount } = render(<div>{node()}</div>)
|
|
96
|
+
expect(container.querySelectorAll('label[aria-describedby], legend[aria-describedby]')).toHaveLength(0)
|
|
97
|
+
unmount()
|
|
98
|
+
}
|
|
99
|
+
})
|
|
100
|
+
})
|
|
@@ -6,6 +6,7 @@ import { PktIcon } from '../icon/Icon'
|
|
|
6
6
|
import { PktInputWrapper } from '../inputwrapper/InputWrapper'
|
|
7
7
|
import { useTimepickerState } from './useTimepickerState'
|
|
8
8
|
import type { IPktTimepicker } from './types'
|
|
9
|
+
import { describedByIds } from 'shared-utils/forms/described-by'
|
|
9
10
|
|
|
10
11
|
export type { IPktTimepicker } from './types'
|
|
11
12
|
|
|
@@ -17,6 +18,11 @@ export const PktTimepicker = forwardRef<HTMLDivElement, IPktTimepicker>((props,
|
|
|
17
18
|
const minutesLabel = state.strings.minutes
|
|
18
19
|
const hoursAriaLabel = state.label ? `${hoursLabel}, ${state.label}` : hoursLabel
|
|
19
20
|
const minutesAriaLabel = state.label ? `${minutesLabel}, ${state.label}` : minutesLabel
|
|
21
|
+
const describedBy = describedByIds({
|
|
22
|
+
id: state.hoursId,
|
|
23
|
+
hasHelptext: !!state.helptext,
|
|
24
|
+
ariaDescribedby: state.ariaDescribedby,
|
|
25
|
+
})
|
|
20
26
|
|
|
21
27
|
const renderOption = (optionValue: number, type: 'hour' | 'minute') => {
|
|
22
28
|
const strVal = String(optionValue).padStart(2, '0')
|
|
@@ -115,6 +121,7 @@ export const PktTimepicker = forwardRef<HTMLDivElement, IPktTimepicker>((props,
|
|
|
115
121
|
role="spinbutton"
|
|
116
122
|
aria-invalid={state.hasError || state.isInvalid || undefined}
|
|
117
123
|
aria-errormessage={state.hasError ? `${state.hoursId}-error` : undefined}
|
|
124
|
+
aria-describedby={describedBy}
|
|
118
125
|
aria-valuemin={0}
|
|
119
126
|
aria-valuemax={23}
|
|
120
127
|
aria-valuenow={state.hours !== '' ? parseInt(state.hours, 10) : undefined}
|
|
@@ -148,6 +155,7 @@ export const PktTimepicker = forwardRef<HTMLDivElement, IPktTimepicker>((props,
|
|
|
148
155
|
role="spinbutton"
|
|
149
156
|
aria-invalid={state.hasError || state.isInvalid || undefined}
|
|
150
157
|
aria-errormessage={state.hasError ? `${state.hoursId}-error` : undefined}
|
|
158
|
+
aria-describedby={describedBy}
|
|
151
159
|
aria-valuemin={0}
|
|
152
160
|
aria-valuemax={59}
|
|
153
161
|
aria-valuenow={state.minutes !== '' ? parseInt(state.minutes, 10) : undefined}
|