@oslokommune/punkt-react 19.19.0 → 19.20.0

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.
@@ -80,6 +80,9 @@ export declare const nb: {
80
80
  tag: {
81
81
  remove: string;
82
82
  };
83
+ progressbar: {
84
+ fraction: string;
85
+ };
83
86
  header: {
84
87
  search: string;
85
88
  menu: string;
@@ -109,6 +109,7 @@ var e = {
109
109
  tagsLabelOther: "merkelapper"
110
110
  },
111
111
  tag: { remove: "Klikk for å fjerne {label}" },
112
+ progressbar: { fraction: "{current} av {total}" },
112
113
  header: {
113
114
  search: "Søk",
114
115
  menu: "Meny",
@@ -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';
@@ -53,7 +55,8 @@ export type { IDatepickerStrings } from './datepicker';
53
55
  export { defaultSingleStrings, defaultRangeStrings } from './datepicker';
54
56
  export type { ITimepickerStrings } from './timepicker';
55
57
  export { defaultTimepickerStrings } from './timepicker';
56
- export type { TProgressbarRole, TProgressbarSkin, TProgressbarStatusPlacement, TProgressbarStatusType, TProgressbarTitlePosition, } from './progressbar';
58
+ export { PROGRESSBAR_DEFAULTS, PROGRESSBAR_ROLES, PROGRESSBAR_SKINS, PROGRESSBAR_STATUS_PLACEMENTS, PROGRESSBAR_STATUS_TYPES, PROGRESSBAR_TITLE_POSITIONS, } from './progressbar';
59
+ export type { IPktProgressbarBase, IProgressbarSpecProps, TProgressbarRole, TProgressbarSkin, TProgressbarStatusPlacement, TProgressbarStatusType, TProgressbarTitlePosition, } from './progressbar';
57
60
  export { COMBOBOX_TAG_SKINS, COMBOBOX_DISPLAY_VALUES, COMBOBOX_TAG_PLACEMENTS, COMBOBOX_DEFAULTS, } from './combobox';
58
61
  export type { IPktComboboxOption, TPktComboboxTagSkin, TPktComboboxDisplayValue, TPktComboboxTagPlacement, IPktComboboxBase, IComboboxSpecProps, } from './combobox';
59
62
  export { SELECT_DEFAULTS } from './select';
@@ -11,9 +11,11 @@ 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";
17
+ import { PROGRESSBAR_DEFAULTS as _ } from "./progressbar.js";
16
18
  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 };
19
+ import { SELECT_DEFAULTS as v } from "./select.js";
20
+ import { TABLE_DEFAULTS as y } from "./table.js";
21
+ 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, _ as PROGRESSBAR_DEFAULTS, o as RADIOBUTTON_DEFAULTS, v as SELECT_DEFAULTS, y as TABLE_DEFAULTS, m as TEXTAREA_DEFAULTS, h as TEXTINPUT_DEFAULTS };
@@ -1,5 +1,82 @@
1
- export type TProgressbarRole = 'progressbar' | 'meter';
2
- export type TProgressbarSkin = 'dark-blue' | 'light-blue' | 'green' | 'red';
3
- export type TProgressbarStatusPlacement = 'center' | 'left' | 'following';
4
- export type TProgressbarStatusType = 'none' | 'percentage' | 'fraction';
5
- export type TProgressbarTitlePosition = 'left' | 'center';
1
+ /**
2
+ * progressbar.ts
3
+ *
4
+ * Shared types and defaults for Progressbar, used by both React and Elements.
5
+ *
6
+ * The value lists are `as const` arrays rather than plain union types. That way
7
+ * the values also exist at runtime, so the component spec and Preview can use
8
+ * them directly (`type: [...PROGRESSBAR_SKINS]`) instead of repeating them.
9
+ * The types are derived from the arrays, so there is a single source.
10
+ */
11
+ import type { IPktStringsProps } from '../shared-strings';
12
+ import type { TAriaLive } from './aria';
13
+ /** Element role: `progressbar` for progress, `meter` for measuring a value. */
14
+ export declare const PROGRESSBAR_ROLES: readonly ['progressbar', 'meter'];
15
+ export type TProgressbarRole = (typeof PROGRESSBAR_ROLES)[number];
16
+ /** Color of the progress bar. */
17
+ export declare const PROGRESSBAR_SKINS: readonly ['dark-blue', 'light-blue', 'green', 'red'];
18
+ export type TProgressbarSkin = (typeof PROGRESSBAR_SKINS)[number];
19
+ /** Where the status text is placed relative to the bar. */
20
+ export declare const PROGRESSBAR_STATUS_PLACEMENTS: readonly ['left', 'following', 'center'];
21
+ export type TProgressbarStatusPlacement = (typeof PROGRESSBAR_STATUS_PLACEMENTS)[number];
22
+ /** How status is shown: none, percentage ("40%") or fraction ("4 av 10"). */
23
+ export declare const PROGRESSBAR_STATUS_TYPES: readonly ['none', 'percentage', 'fraction'];
24
+ export type TProgressbarStatusType = (typeof PROGRESSBAR_STATUS_TYPES)[number];
25
+ /** Alignment of the title above the bar. */
26
+ export declare const PROGRESSBAR_TITLE_POSITIONS: readonly ['left', 'center'];
27
+ export type TProgressbarTitlePosition = (typeof PROGRESSBAR_TITLE_POSITIONS)[number];
28
+ /**
29
+ * Framework-agnostic props for Progressbar.
30
+ *
31
+ * Contains no React or Lit types, so both packages can build on it:
32
+ * React extends it with `HTMLAttributes` and `ref`, Elements uses it as is.
33
+ */
34
+ export interface IPktProgressbarBase extends IPktStringsProps<'progressbar'> {
35
+ /** Accessible name. When set, `aria-labelledby` is not used. */
36
+ ariaLabel?: string | null;
37
+ /** Id of the element that labels the bar. Falls back to the title. */
38
+ ariaLabelledby?: string | null;
39
+ /** How assertively screen readers announce changes. */
40
+ ariaLive?: TAriaLive;
41
+ /** Custom text value. With `statusType="fraction"`, "X av Y" is generated when empty. */
42
+ ariaValueText?: string | null;
43
+ id?: string;
44
+ role?: TProgressbarRole;
45
+ skin?: TProgressbarSkin;
46
+ statusPlacement?: TProgressbarStatusPlacement;
47
+ statusType?: TProgressbarStatusType;
48
+ title?: string | null;
49
+ titlePosition?: TProgressbarTitlePosition;
50
+ /** Current value. Required, since the bar is meaningless without it. */
51
+ valueCurrent: number;
52
+ valueMax?: number;
53
+ valueMin?: number;
54
+ }
55
+ /**
56
+ * Props documented in the component spec (docs and Preview).
57
+ * The spec file is type-checked against this, so a prop that doesn't exist on
58
+ * `IPktProgressbarBase` is a compile error.
59
+ */
60
+ export type IProgressbarSpecProps = Pick<IPktProgressbarBase, 'skin' | 'title' | 'valueMin' | 'valueMax' | 'ariaLabel' | 'ariaLabelledby' | 'ariaValueText' | 'valueCurrent' | 'statusType' | 'statusPlacement' | 'id' | 'titlePosition' | 'role' | 'ariaLive'>;
61
+ /**
62
+ * Default values, shared by React and Elements.
63
+ *
64
+ * These used to be hardcoded in each package and in the JSON spec, and they had
65
+ * drifted apart (the spec said `statusType: 'percentage'`, the components `'none'`).
66
+ * Both components and the spec now read from here.
67
+ *
68
+ * `title` and `id` are left out on purpose: React and Elements handle them
69
+ * differently (Elements generates the id in the property initializer, React
70
+ * via `useGeneratedId`).
71
+ */
72
+ export declare const PROGRESSBAR_DEFAULTS: {
73
+ readonly ariaLive: 'polite';
74
+ readonly role: 'progressbar';
75
+ readonly skin: 'dark-blue';
76
+ readonly statusPlacement: 'following';
77
+ readonly statusType: 'none';
78
+ readonly titlePosition: 'left';
79
+ readonly valueCurrent: 0;
80
+ readonly valueMax: 100;
81
+ readonly valueMin: 0;
82
+ };
@@ -0,0 +1,14 @@
1
+ //#region ../../shared-types/progressbar.ts
2
+ var e = {
3
+ ariaLive: "polite",
4
+ role: "progressbar",
5
+ skin: "dark-blue",
6
+ statusPlacement: "following",
7
+ statusType: "none",
8
+ titlePosition: "left",
9
+ valueCurrent: 0,
10
+ valueMax: 100,
11
+ valueMin: 0
12
+ };
13
+ //#endregion
14
+ export { e as PROGRESSBAR_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.20.0",
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": "0d41efc82367542a5b09c49d9f5894b096c669d0"
107
107
  }
@@ -69,6 +69,31 @@ describe('PktProgressbar', () => {
69
69
  expect(status).toHaveTextContent('50 av 200')
70
70
  })
71
71
 
72
+ test('renders fraction relative to valueMin', () => {
73
+ const { container } = render(
74
+ <PktProgressbar id="progress-min" valueCurrent={25} valueMin={20} valueMax={30} statusType="fraction" />,
75
+ )
76
+ const bar = container.querySelector('.pkt-progressbar')
77
+ const barContainer = container.querySelector<HTMLElement>('.pkt-progressbar__container')
78
+ expect(container.querySelector('.pkt-progressbar__status')).toHaveTextContent('5 av 10')
79
+ expect(bar).toHaveAttribute('aria-valuetext', '5 av 10')
80
+ expect(barContainer?.style.getPropertyValue('--pkt-progress-width')).toBe('50%')
81
+ })
82
+
83
+ test('uses the same bar width for fraction and percentage', () => {
84
+ const props = { valueCurrent: 10, valueMin: 1, valueMax: 10 }
85
+ const { container } = render(
86
+ <>
87
+ <PktProgressbar id="progress-fraction" statusType="fraction" {...props} />
88
+ <PktProgressbar id="progress-percentage" statusType="percentage" {...props} />
89
+ </>,
90
+ )
91
+ const widths = Array.from(container.querySelectorAll<HTMLElement>('.pkt-progressbar__container'), (el) =>
92
+ el.style.getPropertyValue('--pkt-progress-width'),
93
+ )
94
+ expect(widths).toEqual(['100%', '100%'])
95
+ })
96
+
72
97
  test('renders status with center placement', () => {
73
98
  const { container } = render(
74
99
  <PktProgressbar id="progress7" valueCurrent={50} statusType="percentage" statusPlacement="center" />,
@@ -2,15 +2,18 @@
2
2
 
3
3
  import classNames from 'classnames'
4
4
  import { forwardRef, HTMLAttributes, Ref, useEffect, useRef, useState } from 'react'
5
- import type {
6
- TAriaLive,
7
- TProgressbarRole,
8
- TProgressbarSkin,
9
- TProgressbarStatusPlacement,
10
- TProgressbarStatusType,
11
- TProgressbarTitlePosition,
5
+ import {
6
+ PROGRESSBAR_DEFAULTS,
7
+ type IPktProgressbarBase,
8
+ type TProgressbarRole,
9
+ type TProgressbarSkin,
10
+ type TProgressbarStatusPlacement,
11
+ type TProgressbarStatusType,
12
+ type TProgressbarTitlePosition,
12
13
  } from 'shared-types'
14
+ import { formatString } from 'shared-strings'
13
15
  import { useGeneratedId } from '../../hooks/useGeneratedId'
16
+ import { usePktStrings } from '../../hooks/usePktStrings'
14
17
 
15
18
  export type {
16
19
  TProgressbarRole,
@@ -20,21 +23,7 @@ export type {
20
23
  TProgressbarTitlePosition,
21
24
  }
22
25
 
23
- export interface IPktProgressbar extends Omit<HTMLAttributes<HTMLDivElement>, 'role' | 'title'> {
24
- ariaLabel?: string | null
25
- ariaLabelledby?: string | null
26
- ariaLive?: TAriaLive
27
- ariaValueText?: string | null
28
- id?: string
29
- role?: TProgressbarRole
30
- skin?: TProgressbarSkin
31
- statusPlacement?: TProgressbarStatusPlacement
32
- statusType?: TProgressbarStatusType
33
- title?: string | null
34
- titlePosition?: TProgressbarTitlePosition
35
- valueCurrent: number
36
- valueMax?: number
37
- valueMin?: number
26
+ export interface IPktProgressbar extends IPktProgressbarBase, Omit<HTMLAttributes<HTMLDivElement>, 'role' | 'title'> {
38
27
  ref?: Ref<HTMLDivElement>
39
28
  }
40
29
 
@@ -43,24 +32,26 @@ export const PktProgressbar = forwardRef<HTMLDivElement, IPktProgressbar>(
43
32
  {
44
33
  ariaLabel,
45
34
  ariaLabelledby,
46
- ariaLive = 'polite',
35
+ ariaLive = PROGRESSBAR_DEFAULTS.ariaLive,
47
36
  ariaValueText,
48
37
  id,
49
- role = 'progressbar',
50
- skin = 'dark-blue',
51
- statusPlacement = 'following',
52
- statusType = 'none',
38
+ role = PROGRESSBAR_DEFAULTS.role,
39
+ skin = PROGRESSBAR_DEFAULTS.skin,
40
+ statusPlacement = PROGRESSBAR_DEFAULTS.statusPlacement,
41
+ statusType = PROGRESSBAR_DEFAULTS.statusType,
53
42
  title,
54
- titlePosition = 'left',
55
- valueCurrent = 0,
56
- valueMax = 100,
57
- valueMin = 0,
43
+ titlePosition = PROGRESSBAR_DEFAULTS.titlePosition,
44
+ valueCurrent = PROGRESSBAR_DEFAULTS.valueCurrent,
45
+ valueMax = PROGRESSBAR_DEFAULTS.valueMax,
46
+ valueMin = PROGRESSBAR_DEFAULTS.valueMin,
47
+ strings,
58
48
  className,
59
49
  ...props
60
50
  },
61
51
  ref,
62
52
  ) => {
63
53
  const progressbarId = useGeneratedId(id)
54
+ const s = usePktStrings(['progressbar'], strings)
64
55
 
65
56
  const labelRef = useRef<HTMLSpanElement>(null)
66
57
  const [labelWidth, setLabelWidth] = useState(0)
@@ -71,18 +62,17 @@ export const PktProgressbar = forwardRef<HTMLDivElement, IPktProgressbar>(
71
62
  }
72
63
  }, [valueCurrent])
73
64
 
74
- const totalSteps = valueMax - valueMin
75
- const currentPercentage =
76
- statusType === 'fraction'
77
- ? Math.round((valueCurrent / totalSteps) * 100)
78
- : Math.round(((valueCurrent - valueMin) / totalSteps) * 100)
65
+ const totalSteps: number = valueMax - valueMin
66
+ const currentStep = valueCurrent - valueMin
67
+ const currentPercentage = Math.round((currentStep / totalSteps) * 100)
79
68
 
80
- const formattedTitle = `${valueCurrent} av ${totalSteps}`
69
+ const formattedTitle = formatString(s.progressbar.fraction, {
70
+ current: currentStep,
71
+ total: totalSteps,
72
+ })
81
73
 
82
74
  const computedAriaValueText =
83
- statusType === 'fraction' && !ariaValueText
84
- ? `${valueCurrent} av ${valueMax - valueMin}`
85
- : ariaValueText || undefined
75
+ statusType === 'fraction' && !ariaValueText ? formattedTitle : ariaValueText || undefined
86
76
 
87
77
  const computedAriaLabelledby = !ariaLabel ? ariaLabelledby || `${progressbarId}-title` : undefined
88
78
 
@@ -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 && (