@oslokommune/punkt-react 19.19.0 → 19.19.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.
@@ -43,6 +43,8 @@ export type { IHelptextProps, ITagOptionalRequiredProps, IFormFieldLabelProps, I
43
43
  export { COUNTER_POSITIONS, INPUT_WRAPPER_DEFAULTS } from './input-wrapper';
44
44
  export { TEXTAREA_DEFAULTS } from './textarea';
45
45
  export type { IPktTextareaBase, ITextareaSpecProps } from './textarea';
46
+ export { TEXTINPUT_DEFAULTS, TEXTINPUT_TYPES } from './textinput';
47
+ export type { TPktTextinputType, IPktTextinputBase, ITextinputSpecProps } from './textinput';
46
48
  export type { TPktCounterPosition, IPktInputWrapperBase, IInputWrapperSpecProps, } from './input-wrapper';
47
49
  export type { TTagSkin } from './skin';
48
50
  export { MESSAGEBOX_SKINS, MESSAGEBOX_DEFAULTS } from './messagebox';
@@ -11,9 +11,10 @@ import { LOADER_DEFAULTS as d } from "./loader.js";
11
11
  import { ACCORDION_LIGHT_ONLY_SKINS as f } from "./accordion.js";
12
12
  import { INPUT_WRAPPER_DEFAULTS as p } from "./input-wrapper.js";
13
13
  import { TEXTAREA_DEFAULTS as m } from "./textarea.js";
14
- import { MESSAGEBOX_DEFAULTS as h } from "./messagebox.js";
14
+ import { TEXTINPUT_DEFAULTS as h } from "./textinput.js";
15
+ import { MESSAGEBOX_DEFAULTS as g } from "./messagebox.js";
15
16
  import "./calendar.js";
16
17
  import "./combobox.js";
17
- import { SELECT_DEFAULTS as g } from "./select.js";
18
- import { TABLE_DEFAULTS as _ } from "./table.js";
19
- export { f as ACCORDION_LIGHT_ONLY_SKINS, l as ANIMATION_DEFAULT_PATH, i as CARD_DEFAULTS, a as CHECKBOX_DEFAULTS, c as CONSENT_DEFAULTS, n as DEFAULT_FOOTER_PERSONVERN_URL, r as DEFAULT_FOOTER_TILGJENGELIGHET_URL, e as DEFAULT_HEADER_FOOTER_URL, t as DEFAULT_HEADER_LOGO_LINK, u as ICON_DEFAULTS, p as INPUT_WRAPPER_DEFAULTS, d as LOADER_DEFAULTS, h as MESSAGEBOX_DEFAULTS, s as OPTION_GROUP_DEFAULTS, o as RADIOBUTTON_DEFAULTS, g as SELECT_DEFAULTS, _ as TABLE_DEFAULTS, m as TEXTAREA_DEFAULTS };
18
+ import { SELECT_DEFAULTS as _ } from "./select.js";
19
+ import { TABLE_DEFAULTS as v } from "./table.js";
20
+ export { f as ACCORDION_LIGHT_ONLY_SKINS, l as ANIMATION_DEFAULT_PATH, i as CARD_DEFAULTS, a as CHECKBOX_DEFAULTS, c as CONSENT_DEFAULTS, n as DEFAULT_FOOTER_PERSONVERN_URL, r as DEFAULT_FOOTER_TILGJENGELIGHET_URL, e as DEFAULT_HEADER_FOOTER_URL, t as DEFAULT_HEADER_LOGO_LINK, u as ICON_DEFAULTS, p as INPUT_WRAPPER_DEFAULTS, d as LOADER_DEFAULTS, g as MESSAGEBOX_DEFAULTS, s as OPTION_GROUP_DEFAULTS, o as RADIOBUTTON_DEFAULTS, _ as SELECT_DEFAULTS, v as TABLE_DEFAULTS, m as TEXTAREA_DEFAULTS, h as TEXTINPUT_DEFAULTS };
@@ -0,0 +1,82 @@
1
+ /**
2
+ * textinput.ts
3
+ *
4
+ * Type definitions for pkt-textinput.
5
+ * Used by React, Elements, and typed component specs.
6
+ */
7
+ import type { IFormFieldCommonProps } from './form-field';
8
+ import type { TPktInputSize } from './size';
9
+ /** `type`-verdier som dokumenteres for pkt-textinput. Komponenten godtar fortsatt en vanlig streng. */
10
+ export declare const TEXTINPUT_TYPES: readonly ['color', 'date', 'datetime-local', 'email', 'file', 'month', 'number', 'password', 'search', 'tel', 'text', 'time', 'url', 'week'];
11
+ export type TPktTextinputType = (typeof TEXTINPUT_TYPES)[number];
12
+ /**
13
+ * Textinput props shared by React, Elements, and typed component specs.
14
+ *
15
+ * @remarks Keys follow the React prop names. Elements uses lowercase properties instead:
16
+ * `autocomplete`, `minlength`, `maxlength` and `readonly`.
17
+ *
18
+ * React requires `id` and `label`, and widens `helptext`, `helptextDropdown` and
19
+ * `errorMessage` to `ReactNode`.
20
+ * Elements widens `label`, `placeholder`, `size`,
21
+ * `prefix`, `suffix`, `iconNameRight`, `ariaDescribedby`, `ariaLabelledby` and
22
+ * `helptextDropdownButton` to `| null`, `useWrapper` to `Booleanish`, and omits
23
+ * `form`. On Elements `form` is a getter that returns the associated
24
+ * `HTMLFormElement`, not the form id.
25
+ *
26
+ * `counter` and `hasFieldset` are tri-state: `null` means the component derives the value.
27
+ */
28
+ export interface IPktTextinputBase extends IFormFieldCommonProps<'forms' | 'validation'> {
29
+ id?: string;
30
+ name?: string;
31
+ form?: string;
32
+ value?: string;
33
+ placeholder?: string;
34
+ type?: string;
35
+ /** Bredde i antall tegn (HTML-attributtet `size`), ikke den visuelle `inputSize`. */
36
+ size?: number;
37
+ omitSearchIcon?: boolean;
38
+ prefix?: string;
39
+ suffix?: string;
40
+ iconNameRight?: string;
41
+ min?: number | string;
42
+ max?: number | string;
43
+ minLength?: number;
44
+ maxLength?: number;
45
+ step?: number | string;
46
+ readOnly?: boolean;
47
+ autoComplete?: string;
48
+ required?: boolean;
49
+ ariaDescribedby?: string;
50
+ ariaLabelledby?: string;
51
+ inline?: boolean;
52
+ fullwidth?: boolean;
53
+ useWrapper?: boolean;
54
+ counter?: boolean | null;
55
+ counterMaxLength?: number;
56
+ inputSize?: TPktInputSize;
57
+ hasFieldset?: boolean | null;
58
+ }
59
+ /**
60
+ * Documented Textinput props (subset of `IPktTextinputBase`).
61
+ * Used for typed component specs in documentation.
62
+ */
63
+ export type ITextinputSpecProps = Pick<IPktTextinputBase, 'label' | 'name' | 'form' | 'placeholder' | 'helptext' | 'helptextDropdown' | 'helptextDropdownButton' | 'size' | 'type' | 'omitSearchIcon' | 'value' | 'autoComplete' | 'suffix' | 'prefix' | 'iconNameRight' | 'min' | 'max' | 'minLength' | 'maxLength' | 'step' | 'readOnly' | 'ariaLabelledby' | 'ariaDescribedby' | 'required' | 'requiredTag' | 'requiredText' | 'optionalTag' | 'optionalText' | 'tagText' | 'hasError' | 'errorMessage' | 'disabled' | 'inline' | 'fullwidth' | 'useWrapper' | 'id' | 'counter' | 'counterMaxLength' | 'inputSize' | 'hasFieldset'>;
64
+ /**
65
+ * Default values for pkt-textinput. Single source of truth for both frameworks.
66
+ * `counter` and `hasFieldset` are intentionally absent — `null` lets the component derive them.
67
+ */
68
+ export declare const TEXTINPUT_DEFAULTS: {
69
+ readonly type: 'text';
70
+ readonly autoComplete: 'off';
71
+ readonly omitSearchIcon: false;
72
+ readonly required: false;
73
+ readonly readOnly: false;
74
+ readonly requiredTag: false;
75
+ readonly optionalTag: false;
76
+ readonly hasError: false;
77
+ readonly disabled: false;
78
+ readonly inline: false;
79
+ readonly fullwidth: false;
80
+ readonly useWrapper: true;
81
+ readonly inputSize: 'medium';
82
+ };
@@ -0,0 +1,18 @@
1
+ //#region ../../shared-types/textinput.ts
2
+ var e = {
3
+ type: "text",
4
+ autoComplete: "off",
5
+ omitSearchIcon: !1,
6
+ required: !1,
7
+ readOnly: !1,
8
+ requiredTag: !1,
9
+ optionalTag: !1,
10
+ hasError: !1,
11
+ disabled: !1,
12
+ inline: !1,
13
+ fullwidth: !1,
14
+ useWrapper: !0,
15
+ inputSize: "medium"
16
+ };
17
+ //#endregion
18
+ export { e as TEXTINPUT_DEFAULTS };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oslokommune/punkt-react",
3
- "version": "19.19.0",
3
+ "version": "19.19.1",
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",
@@ -103,5 +103,5 @@
103
103
  "url": "https://github.com/oslokommune/punkt/issues"
104
104
  },
105
105
  "license": "MIT",
106
- "gitHead": "44fc3d8f067708fc6704966219994891e9d5f9b3"
106
+ "gitHead": "8373ea76c93221f22496eb298b2382b41bef53ab"
107
107
  }
@@ -75,6 +75,32 @@ describe('PktTextinput', () => {
75
75
  })
76
76
  })
77
77
 
78
+ describe('autocomplete', () => {
79
+ test('defaults to off', () => {
80
+ render(<PktTextinput label={label} id={inputId} />)
81
+
82
+ expect(screen.getByRole('textbox')).toHaveAttribute('autocomplete', 'off')
83
+ })
84
+
85
+ test('sets autocomplete from autoComplete', () => {
86
+ render(<PktTextinput label={label} id={inputId} autoComplete="email" />)
87
+
88
+ expect(screen.getByRole('textbox')).toHaveAttribute('autocomplete', 'email')
89
+ })
90
+
91
+ test('still accepts the autocomplete prop', () => {
92
+ render(<PktTextinput label={label} id={inputId} autocomplete="tel" />)
93
+
94
+ expect(screen.getByRole('textbox')).toHaveAttribute('autocomplete', 'tel')
95
+ })
96
+
97
+ test('autoComplete wins when both props are set', () => {
98
+ render(<PktTextinput label={label} id={inputId} autoComplete="email" autocomplete="tel" />)
99
+
100
+ expect(screen.getByRole('textbox')).toHaveAttribute('autocomplete', 'email')
101
+ })
102
+ })
103
+
78
104
  describe('accessibility', () => {
79
105
  it('renders with no wcag errors with axe', async () => {
80
106
  const { container } = render(<PktTextinput label={label} id={inputId} />)
@@ -12,53 +12,26 @@ import {
12
12
 
13
13
  import { PktIcon } from '../icon/Icon'
14
14
  import { PktInputWrapper } from '../inputwrapper/InputWrapper'
15
+ import { TEXTINPUT_DEFAULTS, type IPktTextinputBase } from 'shared-types'
15
16
  import { describedByIds } from 'shared-utils/forms/described-by'
16
17
  import { useGeneratedId } from '../../hooks/useGeneratedId'
17
- import type { IPktStringsProps } from 'shared-strings'
18
18
 
19
- export interface IPktTextinput extends InputHTMLAttributes<HTMLInputElement>, IPktStringsProps<'forms' | 'validation'> {
19
+ export interface IPktTextinput
20
+ extends
21
+ Omit<IPktTextinputBase, 'helptext' | 'helptextDropdown' | 'errorMessage'>,
22
+ Omit<InputHTMLAttributes<HTMLInputElement>, keyof IPktTextinputBase> {
20
23
  id: string
21
- ariaDescribedby?: string
22
- ariaLabelledby?: string
23
- autocomplete?: string
24
- counter?: boolean
25
- hasFieldset?: boolean
26
- counterMaxLength?: number
27
- disabled?: boolean
24
+ label: string
28
25
  errorMessage?: string | ReactNode | ReactNode[]
29
- hasError?: boolean
30
26
  helptext?: string | ReactNode | ReactNode[]
31
27
  helptextDropdown?: string | ReactNode | ReactNode[]
32
- helptextDropdownButton?: string
33
- iconNameRight?: string
34
- inline?: boolean
35
- fullwidth?: boolean
36
- label: string
37
- name?: string
38
- optionalTag?: boolean
39
- optionalText?: string
40
- requiredTag?: boolean
41
- requiredText?: string
42
- tagText?: string | null
43
- placeholder?: string
44
- prefix?: string
45
- suffix?: string
46
- type?: string
47
- useWrapper?: boolean
48
- value?: string
49
- omitSearchIcon?: boolean
50
- min?: number | string
51
- max?: number | string
52
- minLength?: number
53
- maxLength?: number
54
- step?: string
55
- size?: number
28
+ /** @deprecated Bruk `autoComplete`. */
29
+ autocomplete?: string
30
+ /** @deprecated Bruk `readOnly`. */
56
31
  readonly?: boolean
57
- required?: boolean
58
32
  dataTestid?: string
59
33
  onChange?: ChangeEventHandler<HTMLInputElement>
60
34
  skipForwardTestid?: boolean
61
- inputSize?: 'small' | 'medium' | 'xsmall'
62
35
  }
63
36
 
64
37
  export const PktTextinput = forwardRef(
@@ -67,33 +40,34 @@ export const PktTextinput = forwardRef(
67
40
  id: idProp,
68
41
  ariaDescribedby,
69
42
  ariaLabelledby,
70
- autocomplete = 'off',
43
+ autoComplete,
44
+ autocomplete,
71
45
  counter,
72
46
  hasFieldset,
73
47
  counterMaxLength,
74
48
  className,
75
- disabled = false,
49
+ disabled = TEXTINPUT_DEFAULTS.disabled,
76
50
  errorMessage,
77
- hasError = false,
51
+ hasError = TEXTINPUT_DEFAULTS.hasError,
78
52
  helptext,
79
53
  helptextDropdown,
80
54
  helptextDropdownButton,
81
55
  iconNameRight,
82
- inline = false,
83
- fullwidth = false,
56
+ inline = TEXTINPUT_DEFAULTS.inline,
57
+ fullwidth = TEXTINPUT_DEFAULTS.fullwidth,
84
58
  label,
85
59
  name,
86
- optionalTag = false,
60
+ optionalTag = TEXTINPUT_DEFAULTS.optionalTag,
87
61
  optionalText,
88
- requiredTag = false,
62
+ requiredTag = TEXTINPUT_DEFAULTS.requiredTag,
89
63
  requiredText,
90
64
  tagText = null,
91
65
  placeholder,
92
66
  prefix,
93
67
  suffix,
94
- type = 'text',
95
- useWrapper = true,
96
- omitSearchIcon = false,
68
+ type = TEXTINPUT_DEFAULTS.type,
69
+ useWrapper = TEXTINPUT_DEFAULTS.useWrapper,
70
+ omitSearchIcon = TEXTINPUT_DEFAULTS.omitSearchIcon,
97
71
  value,
98
72
  minLength,
99
73
  maxLength,
@@ -101,12 +75,13 @@ export const PktTextinput = forwardRef(
101
75
  max,
102
76
  step,
103
77
  size,
104
- readonly: readOnly,
105
- required,
78
+ readOnly,
79
+ readonly: readOnlyLegacy,
80
+ required = TEXTINPUT_DEFAULTS.required,
106
81
  dataTestid,
107
82
  onChange,
108
83
  skipForwardTestid = false,
109
- inputSize = 'medium',
84
+ inputSize = TEXTINPUT_DEFAULTS.inputSize,
110
85
  strings,
111
86
  ...props
112
87
  }: IPktTextinput,
@@ -178,7 +153,7 @@ export const PktTextinput = forwardRef(
178
153
  value={isoValue}
179
154
  id={inputId}
180
155
  placeholder={placeholder}
181
- autoComplete={autocomplete}
156
+ autoComplete={autoComplete ?? autocomplete ?? TEXTINPUT_DEFAULTS.autoComplete}
182
157
  disabled={disabled}
183
158
  aria-invalid={hasError}
184
159
  aria-errormessage={hasError ? `${id}-error` : undefined}
@@ -196,7 +171,7 @@ export const PktTextinput = forwardRef(
196
171
  minLength={minLength}
197
172
  maxLength={maxLength}
198
173
  size={size}
199
- readOnly={readOnly}
174
+ readOnly={readOnly ?? readOnlyLegacy ?? TEXTINPUT_DEFAULTS.readOnly}
200
175
  required={required}
201
176
  />
202
177
  {suffix && (