@oslokommune/punkt-react 18.6.0 → 18.6.1
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 +21 -0
- package/dist/punkt-react.cjs +1 -1
- package/dist/punkt-react.js +8 -8
- package/package.json +2 -2
- package/src/components/datepicker/Datepicker.accessibility.test.tsx +9 -5
- package/src/components/datepicker/Datepicker.core.test.tsx +1 -1
- package/src/components/datepicker/Datepicker.selection.test.tsx +23 -0
- package/src/components/datepicker/DatepickerInputs.tsx +6 -7
- package/src/components/datepicker/useDatepickerState.ts +3 -1
package/dist/punkt-react.js
CHANGED
|
@@ -4396,7 +4396,6 @@ var Ar = () => {
|
|
|
4396
4396
|
type: "button",
|
|
4397
4397
|
onClick: M,
|
|
4398
4398
|
disabled: c,
|
|
4399
|
-
"aria-label": C.datepicker.openPicker,
|
|
4400
4399
|
children: [/* @__PURE__ */ _(L, { name: "calendar" }), /* @__PURE__ */ _("span", {
|
|
4401
4400
|
className: "pkt-btn__text",
|
|
4402
4401
|
children: C.datepicker.openPicker
|
|
@@ -4422,9 +4421,9 @@ var Ar = () => {
|
|
|
4422
4421
|
placeholder: p,
|
|
4423
4422
|
readOnly: l || S && !l,
|
|
4424
4423
|
disabled: O,
|
|
4425
|
-
"aria-describedby": h ? `${
|
|
4424
|
+
"aria-describedby": h ? `${n}-helptext` : void 0,
|
|
4426
4425
|
"aria-invalid": m,
|
|
4427
|
-
"aria-errormessage": m ? `${
|
|
4426
|
+
"aria-errormessage": m ? `${n}-error` : void 0,
|
|
4428
4427
|
onClick: R,
|
|
4429
4428
|
onTouchEnd: ce,
|
|
4430
4429
|
onKeyDown: se,
|
|
@@ -4456,9 +4455,9 @@ var Ar = () => {
|
|
|
4456
4455
|
disabled: c,
|
|
4457
4456
|
required: u,
|
|
4458
4457
|
"aria-label": `${d} ${C.generic.from}`,
|
|
4459
|
-
"aria-describedby": h ? `${
|
|
4458
|
+
"aria-describedby": h ? `${n}-helptext` : void 0,
|
|
4460
4459
|
"aria-invalid": m,
|
|
4461
|
-
"aria-errormessage": m ? `${
|
|
4460
|
+
"aria-errormessage": m ? `${n}-error` : void 0,
|
|
4462
4461
|
onClick: R,
|
|
4463
4462
|
onTouchEnd: ce,
|
|
4464
4463
|
onKeyDown: ae,
|
|
@@ -4516,9 +4515,9 @@ var Ar = () => {
|
|
|
4516
4515
|
readOnly: l || S && !l,
|
|
4517
4516
|
disabled: c,
|
|
4518
4517
|
required: u,
|
|
4519
|
-
"aria-describedby": h ? `${
|
|
4518
|
+
"aria-describedby": h ? `${n}-helptext` : void 0,
|
|
4520
4519
|
"aria-invalid": m,
|
|
4521
|
-
"aria-errormessage": m ? `${
|
|
4520
|
+
"aria-errormessage": m ? `${n}-error` : void 0,
|
|
4522
4521
|
onClick: R,
|
|
4523
4522
|
onTouchEnd: ce,
|
|
4524
4523
|
onKeyDown: ie,
|
|
@@ -4582,9 +4581,10 @@ function Ur(e, t) {
|
|
|
4582
4581
|
let $ = o((e, t = !0) => {
|
|
4583
4582
|
U || G(e), t && V?.(e);
|
|
4584
4583
|
}, [U, V]), Ae = f(() => Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, "value")?.set, []), je = o((e) => {
|
|
4584
|
+
if (h && e.length === 1) return;
|
|
4585
4585
|
let t = Y.current;
|
|
4586
4586
|
!t || !Ae || (Ae.call(t, e.join(",")), t.dispatchEvent(new Event("input", { bubbles: !0 })));
|
|
4587
|
-
}, [Ae]), Me = o(() => {
|
|
4587
|
+
}, [Ae, h]), Me = o(() => {
|
|
4588
4588
|
oe || pe((e) => !e);
|
|
4589
4589
|
}, [oe]), Ne = o(() => {
|
|
4590
4590
|
pe(!1);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oslokommune/punkt-react",
|
|
3
|
-
"version": "18.6.
|
|
3
|
+
"version": "18.6.1",
|
|
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",
|
|
@@ -102,5 +102,5 @@
|
|
|
102
102
|
"url": "https://github.com/oslokommune/punkt/issues"
|
|
103
103
|
},
|
|
104
104
|
"license": "MIT",
|
|
105
|
-
"gitHead": "
|
|
105
|
+
"gitHead": "8d641683796be69cb519cfe8ca021731d165e8f1"
|
|
106
106
|
}
|
|
@@ -153,7 +153,7 @@ describe('PktDatepicker', () => {
|
|
|
153
153
|
|
|
154
154
|
const button = container.querySelector('button[type="button"]')
|
|
155
155
|
expect(button).toBeInTheDocument()
|
|
156
|
-
expect(button).
|
|
156
|
+
expect(button).toHaveAccessibleName('Åpne kalender')
|
|
157
157
|
})
|
|
158
158
|
|
|
159
159
|
test('input has aria-describedby when helptext is present', () => {
|
|
@@ -162,7 +162,9 @@ describe('PktDatepicker', () => {
|
|
|
162
162
|
})
|
|
163
163
|
|
|
164
164
|
const input = container.querySelector('input[type="date"]') as HTMLInputElement
|
|
165
|
-
|
|
165
|
+
const describedby = input.getAttribute('aria-describedby')
|
|
166
|
+
expect(describedby).toBe(`${datePickerId}-input-helptext`)
|
|
167
|
+
expect(container.querySelector(`#${describedby}`)).not.toBeNull()
|
|
166
168
|
})
|
|
167
169
|
|
|
168
170
|
test('input does not have aria-describedby when no helptext', () => {
|
|
@@ -189,7 +191,9 @@ describe('PktDatepicker', () => {
|
|
|
189
191
|
})
|
|
190
192
|
|
|
191
193
|
const input = container.querySelector('input[type="date"]') as HTMLInputElement
|
|
192
|
-
|
|
194
|
+
const errormessage = input.getAttribute('aria-errormessage')
|
|
195
|
+
expect(errormessage).toBe(`${datePickerId}-input-error`)
|
|
196
|
+
expect(container.querySelector(`#${errormessage}`)).not.toBeNull()
|
|
193
197
|
})
|
|
194
198
|
|
|
195
199
|
test('input does not have aria-invalid when no error', () => {
|
|
@@ -261,7 +265,7 @@ describe('PktDatepicker', () => {
|
|
|
261
265
|
})
|
|
262
266
|
|
|
263
267
|
const button = container.querySelector('button[type="button"]')
|
|
264
|
-
expect(button).
|
|
268
|
+
expect(button).toHaveAccessibleName('Open calendar')
|
|
265
269
|
})
|
|
266
270
|
|
|
267
271
|
test('uses custom strings for range labels', () => {
|
|
@@ -285,7 +289,7 @@ describe('PktDatepicker', () => {
|
|
|
285
289
|
})
|
|
286
290
|
|
|
287
291
|
const button = container.querySelector('button[type="button"]')
|
|
288
|
-
expect(button).
|
|
292
|
+
expect(button).toHaveAccessibleName('Åpne kalender')
|
|
289
293
|
|
|
290
294
|
const prefix = container.querySelector('.pkt-input-prefix')
|
|
291
295
|
expect(prefix).toHaveTextContent('Fra')
|
|
@@ -72,7 +72,7 @@ describe('PktDatepicker', () => {
|
|
|
72
72
|
|
|
73
73
|
const button = container.querySelector('button[type="button"]')
|
|
74
74
|
expect(button).toBeInTheDocument()
|
|
75
|
-
expect(button).
|
|
75
|
+
expect(button).toHaveAccessibleName('Åpne kalender')
|
|
76
76
|
})
|
|
77
77
|
})
|
|
78
78
|
|
|
@@ -147,6 +147,29 @@ describe('PktDatepicker', () => {
|
|
|
147
147
|
})
|
|
148
148
|
|
|
149
149
|
describe('Range selection', () => {
|
|
150
|
+
test('fires change on a complete range and on clearing, not on the first date', () => {
|
|
151
|
+
const fired: string[] = []
|
|
152
|
+
const { container } = createDatepickerTest({
|
|
153
|
+
range: true,
|
|
154
|
+
calendarOpen: true,
|
|
155
|
+
currentmonth: '2026-01',
|
|
156
|
+
onChange: (e: ChangeEvent<HTMLInputElement>) => fired.push(e.target.value),
|
|
157
|
+
})
|
|
158
|
+
|
|
159
|
+
const days = Array.from(container.querySelectorAll('button')).filter((b) =>
|
|
160
|
+
/^\d+$/.test((b.textContent ?? '').trim()),
|
|
161
|
+
)
|
|
162
|
+
|
|
163
|
+
fireEvent.click(days[14])
|
|
164
|
+
expect(fired).toEqual([])
|
|
165
|
+
|
|
166
|
+
fireEvent.click(days[19])
|
|
167
|
+
expect(fired).toEqual(['2026-01-15,2026-01-20'])
|
|
168
|
+
|
|
169
|
+
fireEvent.click(days[14])
|
|
170
|
+
expect(fired).toEqual(['2026-01-15,2026-01-20', ''])
|
|
171
|
+
})
|
|
172
|
+
|
|
150
173
|
test('renders two inputs for range mode', () => {
|
|
151
174
|
const { container } = createDatepickerTest({
|
|
152
175
|
range: true,
|
|
@@ -64,7 +64,6 @@ export const DatepickerInputs = ({ state }: { state: IDatepickerState }) => {
|
|
|
64
64
|
type="button"
|
|
65
65
|
onClick={toggleCalendar}
|
|
66
66
|
disabled={disabled}
|
|
67
|
-
aria-label={strings.datepicker.openPicker}
|
|
68
67
|
>
|
|
69
68
|
<PktIcon name="calendar" />
|
|
70
69
|
<span className="pkt-btn__text">{strings.datepicker.openPicker}</span>
|
|
@@ -93,9 +92,9 @@ export const DatepickerInputs = ({ state }: { state: IDatepickerState }) => {
|
|
|
93
92
|
placeholder={placeholder}
|
|
94
93
|
readOnly={readOnly || (isIOSDevice && !readOnly)}
|
|
95
94
|
disabled={isInputDisabled}
|
|
96
|
-
aria-describedby={helptext ? `${
|
|
95
|
+
aria-describedby={helptext ? `${inputId}-helptext` : undefined}
|
|
97
96
|
aria-invalid={hasError}
|
|
98
|
-
aria-errormessage={hasError ? `${
|
|
97
|
+
aria-errormessage={hasError ? `${inputId}-error` : undefined}
|
|
99
98
|
onClick={handleInputClick}
|
|
100
99
|
onTouchEnd={handleInputTouchEnd}
|
|
101
100
|
onKeyDown={handleMultipleKeydown}
|
|
@@ -129,9 +128,9 @@ export const DatepickerInputs = ({ state }: { state: IDatepickerState }) => {
|
|
|
129
128
|
disabled={disabled}
|
|
130
129
|
required={required}
|
|
131
130
|
aria-label={`${label} ${strings.generic.from}`}
|
|
132
|
-
aria-describedby={helptext ? `${
|
|
131
|
+
aria-describedby={helptext ? `${inputId}-helptext` : undefined}
|
|
133
132
|
aria-invalid={hasError}
|
|
134
|
-
aria-errormessage={hasError ? `${
|
|
133
|
+
aria-errormessage={hasError ? `${inputId}-error` : undefined}
|
|
135
134
|
onClick={handleInputClick}
|
|
136
135
|
onTouchEnd={handleInputTouchEnd}
|
|
137
136
|
onKeyDown={handleRangeFromKeydown}
|
|
@@ -187,9 +186,9 @@ export const DatepickerInputs = ({ state }: { state: IDatepickerState }) => {
|
|
|
187
186
|
readOnly={readOnly || (isIOSDevice && !readOnly)}
|
|
188
187
|
disabled={disabled}
|
|
189
188
|
required={required}
|
|
190
|
-
aria-describedby={helptext ? `${
|
|
189
|
+
aria-describedby={helptext ? `${inputId}-helptext` : undefined}
|
|
191
190
|
aria-invalid={hasError}
|
|
192
|
-
aria-errormessage={hasError ? `${
|
|
191
|
+
aria-errormessage={hasError ? `${inputId}-error` : undefined}
|
|
193
192
|
onClick={handleInputClick}
|
|
194
193
|
onTouchEnd={handleInputTouchEnd}
|
|
195
194
|
onKeyDown={handleSingleKeydown}
|
|
@@ -188,12 +188,14 @@ export function useDatepickerState(props: IPktDatepicker, ref: React.ForwardedRe
|
|
|
188
188
|
|
|
189
189
|
const dispatchChange = useCallback(
|
|
190
190
|
(newValues: string[]) => {
|
|
191
|
+
// Én dato er ingen fullført periode. Tom er en fullført endring.
|
|
192
|
+
if (range && newValues.length === 1) return
|
|
191
193
|
const input = changeInputRef.current
|
|
192
194
|
if (!input || !nativeInputValueSetter) return
|
|
193
195
|
nativeInputValueSetter.call(input, newValues.join(','))
|
|
194
196
|
input.dispatchEvent(new Event('input', { bubbles: true }))
|
|
195
197
|
},
|
|
196
|
-
[nativeInputValueSetter],
|
|
198
|
+
[nativeInputValueSetter, range],
|
|
197
199
|
)
|
|
198
200
|
|
|
199
201
|
// Calendar toggle
|