@oslokommune/punkt-react 20.1.0 → 20.1.3

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 CHANGED
@@ -5,6 +5,29 @@ og skriver commits ca etter [Conventional Commits](https://conventionalcommits.o
5
5
 
6
6
  ---
7
7
 
8
+ ## [20.1.3](https://github.com/oslokommune/punkt/compare/20.1.2...20.1.3) (2026-11-11)
9
+
10
+ ### Bug Fixes
11
+ * Datepicker TS Spec + Gjør datepicker lik i React og Elements (#3822). - Kalenderen plasseres likt i begge, og vises over feltet når det ikke
12
+ er plass under
13
+ - `focus` og `blur` sendes en gang per inn/ut, og fokus går tilbake til
14
+ feltet etter valgt dato og Escape. react-hook-form får nå med seg blur i
15
+ React
16
+ - Telleren kan slås av og på i begge, og `maxlength` 0 betyr ingen
17
+ grense
18
+ - Tømmes til-datoen i en periode, beholdes fra-datoen. En til-dato uten
19
+ fra-dato blir stående mens brukeren er i feltet, og fjernes når de går
20
+ ut
21
+ - Elements sender én verdi per dato i skjemaet, også når feltet er
22
+ forhåndsutfylt, slik dokumentasjonen sier. React sender én kommaseparert
23
+ verdi uten ekstra `-from`/`-to` og tomme verdier
24
+ - Spesifikasjonen er flyttet fra JSON til TypeScript, og dokumentasjonen
25
+ er oppdatert
26
+ - Kalenderen viser ikke en periode før den er komplett
27
+
28
+ ---
29
+
30
+
8
31
  ## [20.1.0](https://github.com/oslokommune/punkt/compare/20.0.5...20.1.0) (2026-11-09)
9
32
 
10
33
  ### Features
@@ -14,8 +14,11 @@ var s = i((i, s) => {
14
14
  c.className
15
15
  ].filter(Boolean).join(" ");
16
16
  return /* @__PURE__ */ o("div", {
17
+ ref: c.rootRef,
17
18
  className: l,
18
19
  id: c.id || void 0,
20
+ onFocus: c.reportFocusChange,
21
+ onBlur: c.reportFocusChange,
19
22
  children: [
20
23
  /* @__PURE__ */ a(e, {
21
24
  strings: c.stringsOverride,
@@ -49,7 +52,7 @@ var s = i((i, s) => {
49
52
  range: c.range,
50
53
  weeknumbers: c.weeknumbers,
51
54
  withcontrols: c.withcontrols,
52
- selected: c.values,
55
+ selected: c.calendarSelected,
53
56
  earliest: c.minStr,
54
57
  latest: c.maxStr,
55
58
  excludedates: c.excludedates,
@@ -65,8 +68,11 @@ var s = i((i, s) => {
65
68
  /* @__PURE__ */ a("input", {
66
69
  ref: c.changeInputRef,
67
70
  type: "text",
68
- name: c.name,
71
+ name: c.name ?? c.id,
72
+ form: i.form,
69
73
  onChange: c.onChange,
74
+ onFocus: c.onFocus,
75
+ onBlur: c.onBlur,
70
76
  tabIndex: -1,
71
77
  "aria-hidden": "true",
72
78
  className: "pkt-visually-hidden"
@@ -3,26 +3,26 @@ import { DateTags as t } from "./DateTags.js";
3
3
  import { Fragment as n, jsx as r, jsxs as i } from "react/jsx-runtime";
4
4
  // src/components/datepicker/DatepickerInputs.tsx
5
5
  var a = ({ state: a }) => {
6
- let { id: o, inputId: s, values: c, dateformat: l, multiple: u, range: d, showRangeLabels: f, disabled: p, readOnly: m, required: h, label: g, name: _, placeholder: v, hasError: y, helptext: b, minStr: x, maxStr: S, inputType: C, isIOSDevice: w, strings: T, inputClasses: E, buttonClasses: D, rangeLabelClasses: O, datepickerInputsClasses: k, isInputDisabled: A, inputRef: j, inputToRef: M, btnRef: N, toggleCalendar: P, handleFocus: F, handleSingleInputChange: I, handleRangeFromChange: L, handleRangeToChange: R, handleRangeBlur: z, handleMultipleBlur: B, handleTagRemoved: V, handleSingleKeydown: H, handleRangeFromKeydown: U, handleRangeToKeydown: W, handleMultipleKeydown: G, restProps: K } = a, q = (e) => {
7
- e.preventDefault(), P();
6
+ let { id: o, inputId: s, values: c, dateformat: l, multiple: u, range: d, showRangeLabels: f, disabled: p, readOnly: m, required: h, label: g, placeholder: _, hasError: v, helptext: y, minStr: b, maxStr: x, inputType: S, isIOSDevice: C, strings: w, inputClasses: T, buttonClasses: E, rangeLabelClasses: D, datepickerInputsClasses: O, isInputDisabled: k, inputRef: A, inputToRef: j, btnRef: M, toggleCalendar: N, handleFocus: P, handleSingleInputChange: F, handleRangeFromChange: I, handleRangeToChange: L, handleRangeBlur: R, rangeToValue: z, handleMultipleBlur: B, handleTagRemoved: V, handleSingleKeydown: H, handleRangeFromKeydown: U, handleRangeToKeydown: W, handleMultipleKeydown: G, restProps: K } = a, q = (e) => {
7
+ e.preventDefault(), N();
8
8
  }, J = (e) => {
9
- e.preventDefault(), P();
9
+ e.preventDefault(), N();
10
10
  }, Y = () => /* @__PURE__ */ i("button", {
11
- ref: N,
12
- className: D,
11
+ ref: M,
12
+ className: E,
13
13
  type: "button",
14
- onClick: P,
14
+ onClick: N,
15
15
  disabled: p,
16
16
  children: [/* @__PURE__ */ r(e, { name: "calendar" }), /* @__PURE__ */ r("span", {
17
17
  className: "pkt-btn__text",
18
- children: T.datepicker.openPicker
18
+ children: w.datepicker.openPicker
19
19
  })]
20
20
  });
21
21
  return u ? /* @__PURE__ */ i(n, { children: [/* @__PURE__ */ r(t, {
22
22
  dates: c,
23
23
  dateformat: l,
24
24
  idBase: o,
25
- strings: T,
25
+ strings: w,
26
26
  onDateRemoved: V
27
27
  }), /* @__PURE__ */ r("div", {
28
28
  className: "pkt-datepicker__inputs",
@@ -30,86 +30,83 @@ var a = ({ state: a }) => {
30
30
  className: "pkt-input__container",
31
31
  children: [/* @__PURE__ */ r("input", {
32
32
  ...K,
33
- ref: j,
34
- className: E,
35
- type: C,
33
+ ref: A,
34
+ className: T,
35
+ type: S,
36
36
  id: s,
37
- name: _ ?? o,
38
- placeholder: v,
39
- readOnly: m || w && !m,
40
- disabled: A,
41
- "aria-describedby": b ? `${s}-helptext` : void 0,
42
- "aria-invalid": y,
43
- "aria-errormessage": y ? `${s}-error` : void 0,
37
+ placeholder: _,
38
+ readOnly: m || C && !m,
39
+ disabled: k,
40
+ "aria-describedby": y ? `${s}-helptext` : void 0,
41
+ "aria-invalid": v,
42
+ "aria-errormessage": v ? `${s}-error` : void 0,
44
43
  onClick: q,
45
44
  onTouchEnd: J,
46
45
  onKeyDown: G,
47
- onFocus: F,
46
+ onFocus: P,
48
47
  onBlur: B
49
48
  }), Y()]
50
49
  })
51
50
  })] }) : d ? /* @__PURE__ */ r("div", {
52
- className: k,
51
+ className: O,
53
52
  children: /* @__PURE__ */ i("div", {
54
53
  className: "pkt-input__container",
55
54
  children: [
56
55
  f && /* @__PURE__ */ r("div", {
57
56
  className: "pkt-input-prefix",
58
- children: T.generic.from
57
+ children: w.generic.from
59
58
  }),
60
59
  /* @__PURE__ */ r("input", {
61
60
  ...K,
62
- ref: j,
63
- className: E,
64
- type: C,
61
+ ref: A,
62
+ className: T,
63
+ type: S,
65
64
  id: s,
66
- name: _ ? `${_}-from` : `${o}-from`,
67
65
  value: c[0] ?? "",
68
- min: x,
69
- max: S,
70
- placeholder: v,
71
- readOnly: m || w && !m,
66
+ min: b,
67
+ max: x,
68
+ placeholder: _,
69
+ readOnly: m || C && !m,
72
70
  disabled: p,
73
71
  required: h,
74
- "aria-label": `${g} ${T.generic.from}`,
75
- "aria-describedby": b ? `${s}-helptext` : void 0,
76
- "aria-invalid": y,
77
- "aria-errormessage": y ? `${s}-error` : void 0,
72
+ "aria-label": `${g} ${w.generic.from}`,
73
+ "aria-describedby": y ? `${s}-helptext` : void 0,
74
+ "aria-invalid": v,
75
+ "aria-errormessage": v ? `${s}-error` : void 0,
78
76
  onClick: q,
79
77
  onTouchEnd: J,
80
78
  onKeyDown: U,
81
- onFocus: F,
82
- onBlur: z,
83
- onChange: L
79
+ onFocus: P,
80
+ onBlur: R,
81
+ onChange: I
84
82
  }),
85
83
  /* @__PURE__ */ r("div", {
86
- className: O,
84
+ className: D,
87
85
  id: `${o}-to-label`,
88
- children: T.generic.to
86
+ children: w.generic.to
89
87
  }),
90
88
  !f && /* @__PURE__ */ r("div", {
91
89
  className: "pkt-input-separator",
92
90
  children: "–"
93
91
  }),
94
92
  /* @__PURE__ */ r("input", {
95
- ref: M,
96
- className: E,
97
- type: C,
93
+ ref: j,
94
+ className: T,
95
+ type: S,
98
96
  id: `${o}-to`,
99
- name: _ ? `${_}-to` : `${o}-to`,
100
- value: c[1] ?? "",
101
- min: x,
102
- max: S,
103
- readOnly: m || w && !m,
97
+ value: z,
98
+ min: b,
99
+ max: x,
100
+ readOnly: m || C && !m,
104
101
  disabled: p,
105
- "aria-label": `${g} ${T.generic.to}`,
106
- "aria-invalid": y,
102
+ "aria-label": `${g} ${w.generic.to}`,
103
+ "aria-invalid": v,
107
104
  onClick: q,
108
105
  onTouchEnd: J,
109
106
  onKeyDown: W,
110
- onFocus: F,
111
- onBlur: z,
112
- onChange: R
107
+ onFocus: P,
108
+ onBlur: R,
109
+ onChange: L
113
110
  }),
114
111
  Y()
115
112
  ]
@@ -120,27 +117,26 @@ var a = ({ state: a }) => {
120
117
  className: "pkt-input__container",
121
118
  children: [/* @__PURE__ */ r("input", {
122
119
  ...K,
123
- ref: j,
124
- className: E,
125
- type: C,
120
+ ref: A,
121
+ className: T,
122
+ type: S,
126
123
  id: s,
127
- name: _ ?? o,
128
124
  value: c[0] ?? "",
129
- min: x,
130
- max: S,
131
- placeholder: v,
132
- readOnly: m || w && !m,
125
+ min: b,
126
+ max: x,
127
+ placeholder: _,
128
+ readOnly: m || C && !m,
133
129
  disabled: p,
134
130
  required: h,
135
- "aria-describedby": b ? `${s}-helptext` : void 0,
136
- "aria-invalid": y,
137
- "aria-errormessage": y ? `${s}-error` : void 0,
131
+ "aria-describedby": y ? `${s}-helptext` : void 0,
132
+ "aria-invalid": v,
133
+ "aria-errormessage": v ? `${s}-error` : void 0,
138
134
  onClick: q,
139
135
  onTouchEnd: J,
140
136
  onKeyDown: H,
141
- onFocus: F,
137
+ onFocus: P,
142
138
  onBlur: void 0,
143
- onChange: I
139
+ onChange: F
144
140
  }), Y()]
145
141
  })
146
142
  });
@@ -1,44 +1,16 @@
1
- import { TPktStrings, IPktStringsProps, TPktStringsOverride } from '../../shared-strings';
2
- import { ChangeEvent, InputHTMLAttributes, ReactNode } from 'react';
1
+ import { TPktStrings, TPktStringsOverride } from '../../shared-strings';
2
+ import { ChangeEvent, FocusEventHandler, InputHTMLAttributes, ReactNode } from 'react';
3
+ import { IPktDatepickerBase, TDatepickerStringsNamespace } from '../../shared-types';
3
4
  import { TPktInputSize } from '../../shared-types/size';
4
- export type TDatepickerStrings = 'generic' | 'datepicker' | 'validation' | 'forms' | 'dates' | 'calendar';
5
- export interface IPktDatepicker extends Omit<InputHTMLAttributes<HTMLInputElement>, 'value' | 'onChange'>, IPktStringsProps<TDatepickerStrings> {
5
+ export type TDatepickerStrings = TDatepickerStringsNamespace;
6
+ export interface IPktDatepicker extends Omit<IPktDatepickerBase, 'helptext' | 'helptextDropdown' | 'errorMessage'>, Omit<InputHTMLAttributes<HTMLInputElement>, keyof IPktDatepickerBase | 'onChange'> {
6
7
  id: string;
7
8
  label: string;
8
- ariaDescribedby?: string;
9
- value?: string | string[];
10
- dateformat?: string;
11
- multiple?: boolean;
12
- maxlength?: number;
13
- range?: boolean;
14
- showRangeLabels?: boolean;
15
- weeknumbers?: boolean;
16
- withcontrols?: boolean;
17
- excludedates?: string[];
18
- excludeweekdays?: string[];
19
- currentmonth?: string;
20
- today?: string;
21
- calendarOpen?: boolean;
22
- timezone?: string;
23
- fullwidth?: boolean;
24
- inputSize?: TPktInputSize;
25
- hasFieldset?: boolean;
26
- inline?: boolean;
27
- counter?: boolean;
28
9
  helptext?: string | ReactNode;
29
10
  helptextDropdown?: string | ReactNode;
30
- helptextDropdownButton?: string;
31
- hasError?: boolean;
32
11
  errorMessage?: string | ReactNode;
33
- optionalTag?: boolean;
34
- optionalText?: string;
35
- requiredTag?: boolean;
36
- requiredText?: string;
37
- tagText?: string;
38
- useWrapper?: boolean;
39
12
  onChange?: (e: ChangeEvent<HTMLInputElement>) => void;
40
13
  onValueChange?: (values: string[]) => void;
41
- className?: string;
42
14
  }
43
15
  export interface IDatepickerState {
44
16
  id: string;
@@ -73,7 +45,7 @@ export interface IDatepickerState {
73
45
  optionalText?: string;
74
46
  requiredTag: boolean;
75
47
  requiredText?: string;
76
- tagText?: string;
48
+ tagText?: string | null;
77
49
  useWrapper: boolean;
78
50
  className?: string;
79
51
  minStr?: string;
@@ -96,7 +68,11 @@ export interface IDatepickerState {
96
68
  changeInputRef: React.RefObject<HTMLInputElement | null>;
97
69
  btnRef: React.RefObject<HTMLButtonElement | null>;
98
70
  wrapperRef: React.RefObject<HTMLDivElement | null>;
71
+ rootRef: React.RefObject<HTMLDivElement | null>;
99
72
  onChange?: (e: ChangeEvent<HTMLInputElement>) => void;
73
+ onFocus?: FocusEventHandler<HTMLInputElement>;
74
+ onBlur?: FocusEventHandler<HTMLInputElement>;
75
+ reportFocusChange: FocusEventHandler<HTMLDivElement>;
100
76
  toggleCalendar: () => void;
101
77
  hideCalendar: () => void;
102
78
  handleDateSelected: (selected: string[]) => void;
@@ -106,6 +82,8 @@ export interface IDatepickerState {
106
82
  handleRangeFromChange: (e: React.ChangeEvent<HTMLInputElement>) => void;
107
83
  handleRangeToChange: (e: React.ChangeEvent<HTMLInputElement>) => void;
108
84
  handleRangeBlur: () => void;
85
+ rangeToValue: string;
86
+ calendarSelected: string[];
109
87
  handleMultipleBlur: (e: React.FocusEvent<HTMLInputElement>) => void;
110
88
  handleTagRemoved: (date: string) => void;
111
89
  handleSingleKeydown: (e: React.KeyboardEvent<HTMLInputElement>) => void;