@oslokommune/punkt-react 19.17.1 → 19.18.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.
@@ -39,6 +39,8 @@ export type { IRenderLink, TRenderLink } from './render-link';
39
39
  export type { IPktStringsProps } from '../shared-strings';
40
40
  export type { IHelptextProps, ITagOptionalRequiredProps, IFormFieldLabelProps, IFormFieldErrorProps, IFormFieldCommonProps, TFormFieldCommonSpecKeys, } from './form-field';
41
41
  export { COUNTER_POSITIONS, INPUT_WRAPPER_DEFAULTS } from './input-wrapper';
42
+ export { TEXTAREA_DEFAULTS } from './textarea';
43
+ export type { IPktTextareaBase, ITextareaSpecProps } from './textarea';
42
44
  export type { TPktCounterPosition, IPktInputWrapperBase, IInputWrapperSpecProps, } from './input-wrapper';
43
45
  export type { TTagSkin } from './skin';
44
46
  export { MESSAGEBOX_SKINS, MESSAGEBOX_DEFAULTS } from './messagebox';
@@ -0,0 +1,67 @@
1
+ /**
2
+ * textarea.ts
3
+ *
4
+ * Type definitions for pkt-textarea.
5
+ * Used by React, Elements, and typed component specs.
6
+ */
7
+ import type { IFormFieldCommonProps } from './form-field';
8
+ import type { TPktInputSize } from './size';
9
+ /**
10
+ * Textarea props shared by React, Elements, and typed component specs.
11
+ *
12
+ * @remarks Keys follow the React prop names. Elements uses lowercase properties instead:
13
+ * `autocomplete`, `minlength`, `maxlength` and `readonly`.
14
+ *
15
+ * React requires `id` and `label`, and widens `helptext`, `helptextDropdown` and
16
+ * `errorMessage` to `ReactNode`. Elements widens `label`, `placeholder`, `rows`, `cols`,
17
+ * `ariaDescribedby`, `ariaLabelledby` and `helptextDropdownButton` to `| null` (Lit uses
18
+ * `null` for an unset attribute), `useWrapper` to `Booleanish`, and omits `form`, which is
19
+ * a getter returning the associated `HTMLFormElement`, not the form id.
20
+ *
21
+ * `counter` and `hasFieldset` are tri-state: `null` means the component derives the value.
22
+ */
23
+ export interface IPktTextareaBase extends IFormFieldCommonProps<'forms' | 'validation'> {
24
+ id?: string;
25
+ name?: string;
26
+ form?: string;
27
+ value?: string;
28
+ placeholder?: string;
29
+ rows?: number;
30
+ cols?: number;
31
+ minLength?: number;
32
+ maxLength?: number;
33
+ readOnly?: boolean;
34
+ autoComplete?: string;
35
+ required?: boolean;
36
+ ariaDescribedby?: string;
37
+ ariaLabelledby?: string;
38
+ inline?: boolean;
39
+ fullwidth?: boolean;
40
+ useWrapper?: boolean;
41
+ counter?: boolean | null;
42
+ counterMaxLength?: number;
43
+ inputSize?: TPktInputSize;
44
+ hasFieldset?: boolean | null;
45
+ }
46
+ /**
47
+ * Documented Textarea props (subset of `IPktTextareaBase`).
48
+ * Used for typed component specs in documentation.
49
+ */
50
+ export type ITextareaSpecProps = Pick<IPktTextareaBase, 'label' | 'name' | 'form' | 'placeholder' | 'helptext' | 'helptextDropdown' | 'helptextDropdownButton' | 'rows' | 'cols' | 'minLength' | 'maxLength' | 'readOnly' | 'value' | 'autoComplete' | 'ariaLabelledby' | 'ariaDescribedby' | 'required' | 'requiredTag' | 'requiredText' | 'optionalTag' | 'optionalText' | 'tagText' | 'hasError' | 'errorMessage' | 'disabled' | 'inline' | 'fullwidth' | 'useWrapper' | 'id' | 'counter' | 'counterMaxLength' | 'inputSize' | 'hasFieldset'>;
51
+ /**
52
+ * Default values for pkt-textarea. Single source of truth for both frameworks.
53
+ * `counter` and `hasFieldset` are intentionally absent — `null` lets the component derive them.
54
+ */
55
+ export declare const TEXTAREA_DEFAULTS: {
56
+ readonly autoComplete: 'off';
57
+ readonly required: false;
58
+ readonly readOnly: false;
59
+ readonly requiredTag: false;
60
+ readonly optionalTag: false;
61
+ readonly hasError: false;
62
+ readonly disabled: false;
63
+ readonly inline: false;
64
+ readonly fullwidth: false;
65
+ readonly useWrapper: true;
66
+ readonly inputSize: 'medium';
67
+ };
@@ -0,0 +1,16 @@
1
+ //#region ../../shared-types/textarea.ts
2
+ var e = {
3
+ autoComplete: "off",
4
+ required: !1,
5
+ readOnly: !1,
6
+ requiredTag: !1,
7
+ optionalTag: !1,
8
+ hasError: !1,
9
+ disabled: !1,
10
+ inline: !1,
11
+ fullwidth: !1,
12
+ useWrapper: !0,
13
+ inputSize: "medium"
14
+ };
15
+ //#endregion
16
+ export { e as TEXTAREA_DEFAULTS };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oslokommune/punkt-react",
3
- "version": "19.17.1",
3
+ "version": "19.18.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",
@@ -102,5 +102,5 @@
102
102
  "url": "https://github.com/oslokommune/punkt/issues"
103
103
  },
104
104
  "license": "MIT",
105
- "gitHead": "fd4bf55becbedfdf8ee1de536d4f3e8a3b50c134"
105
+ "gitHead": "6b3cae25111200ae8f8f3673e13c8b6379337ecf"
106
106
  }
@@ -54,6 +54,7 @@ export { PktTabs } from './tabs/Tabs'
54
54
  export { PktTabItem } from './tabs/TabItem'
55
55
  export { PktTag } from './tag/Tag'
56
56
  export { PktTextarea } from './textarea/Textarea'
57
+ export type { IPktTextarea } from './textarea/Textarea'
57
58
  export { PktTextinput } from './textinput/Textinput'
58
59
  export { PktTimepicker } from './timepicker/Timepicker'
59
60
  export * from './interfaces'
@@ -31,8 +31,9 @@ describe('PktTextarea', () => {
31
31
 
32
32
  test('renders error message when hasError prop is true', async () => {
33
33
  render(<PktTextarea label="Input Label" id="inputId" hasError errorMessage="Input error" />)
34
- const errorMessageId = 'inputId-input-error' // når https://github.com/oslokommune/punkt/issues/3093 er fiksa: screen.getByRole('textbox').getAttribute('aria-errormessage')
34
+ const errorMessageId = screen.getByRole('textbox').getAttribute('aria-errormessage')
35
35
  const alertContainer = screen.getByRole('alert')
36
+ expect(errorMessageId).toBe('inputId-input-error')
36
37
  expect(alertContainer).toHaveAttribute('id', errorMessageId)
37
38
  expect(alertContainer).toHaveTextContent('Input error')
38
39
  })
@@ -79,5 +80,45 @@ describe('PktTextarea', () => {
79
80
  const results = await axe(container)
80
81
  expect(results).toHaveNoViolations()
81
82
  })
83
+
84
+ it('renders with no wcag errors with axe in error state with helptext and counter', async () => {
85
+ const { container } = render(
86
+ <PktTextarea
87
+ label="Input Label"
88
+ id="inputId"
89
+ helptext="Help Text"
90
+ counter
91
+ counterMaxLength={10}
92
+ hasError
93
+ errorMessage="Input error"
94
+ />,
95
+ )
96
+ const results = await axe(container)
97
+ expect(results).toHaveNoViolations()
98
+ })
99
+
100
+ it('exposes the label as accessible name', () => {
101
+ render(<PktTextarea label="Input Label" id="inputId" />)
102
+ expect(screen.getByRole('textbox', { name: 'Input Label' })).toBeInTheDocument()
103
+ })
104
+
105
+ it('exposes helptext as accessible description', () => {
106
+ render(<PktTextarea label="Input Label" id="inputId" helptext="Help Text" />)
107
+ expect(screen.getByRole('textbox')).toHaveAccessibleDescription(/Help Text/)
108
+ })
109
+
110
+ it('links the error message to the textarea', () => {
111
+ render(<PktTextarea label="Input Label" id="inputId" hasError errorMessage="Input error" />)
112
+ const textarea = screen.getByRole('textbox')
113
+ expect(textarea).toHaveAttribute('aria-invalid', 'true')
114
+ expect(textarea).toHaveAccessibleErrorMessage('Input error')
115
+ })
116
+
117
+ it('does not expose an error message without hasError', () => {
118
+ render(<PktTextarea label="Input Label" id="inputId" errorMessage="Input error" />)
119
+ const textarea = screen.getByRole('textbox')
120
+ expect(textarea).toHaveAttribute('aria-invalid', 'false')
121
+ expect(textarea).not.toHaveAttribute('aria-errormessage')
122
+ })
82
123
  })
83
124
  })
@@ -11,45 +11,22 @@ import {
11
11
  } from 'react'
12
12
 
13
13
  import { PktInputWrapper } from '../inputwrapper/InputWrapper'
14
- import { TPktInputSize } from 'shared-types/size'
14
+ import { TEXTAREA_DEFAULTS, type IPktTextareaBase } from 'shared-types'
15
15
  import { describedByIds } from 'shared-utils/forms/described-by'
16
16
  import { useGeneratedId } from '../../hooks/useGeneratedId'
17
- import type { IPktStringsProps } from 'shared-strings'
18
17
 
19
18
  export interface IPktTextarea
20
- extends TextareaHTMLAttributes<HTMLTextAreaElement>, IPktStringsProps<'forms' | 'validation'> {
19
+ extends
20
+ Omit<IPktTextareaBase, 'helptext' | 'helptextDropdown' | 'errorMessage'>,
21
+ Omit<TextareaHTMLAttributes<HTMLTextAreaElement>, keyof IPktTextareaBase> {
21
22
  id: string
22
- ariaDescribedby?: string
23
- ariaLabelledby?: string
24
- counter?: boolean
25
- hasFieldset?: boolean
26
- counterMaxLength?: number
27
- disabled?: boolean
23
+ label: string
28
24
  errorMessage?: string | ReactNode | ReactNode[]
29
- hasError?: boolean
30
25
  helptext?: string | ReactNode | ReactNode[]
31
26
  helptextDropdown?: string | ReactNode | ReactNode[]
32
- helptextDropdownButton?: string
33
- inline?: boolean
34
- fullwidth?: boolean
35
- label: string
36
- name?: string
37
- optionalTag?: boolean
38
- optionalText?: string
39
- requiredTag?: boolean
40
- requiredText?: string
41
- tagText?: string | null
42
- placeholder?: string
43
- rows?: number
44
- useWrapper?: boolean
45
- value?: string
27
+ /** @deprecated Bruk `autoComplete`. */
46
28
  autocomplete?: string
47
- minLength?: number
48
- maxLength?: number
49
- readOnly?: boolean
50
- required?: boolean
51
29
  skipForwardTestid?: boolean
52
- inputSize?: TPktInputSize
53
30
  onChange?: ChangeEventHandler<HTMLTextAreaElement>
54
31
  }
55
32
 
@@ -65,30 +42,31 @@ export const PktTextarea = forwardRef(
65
42
  className,
66
43
  disabled,
67
44
  errorMessage,
68
- hasError = false,
45
+ hasError = TEXTAREA_DEFAULTS.hasError,
69
46
  helptext,
70
47
  helptextDropdown,
71
48
  helptextDropdownButton,
72
49
  inline,
73
- fullwidth = false,
50
+ fullwidth = TEXTAREA_DEFAULTS.fullwidth,
74
51
  label,
75
52
  name,
76
- optionalTag = false,
53
+ optionalTag = TEXTAREA_DEFAULTS.optionalTag,
77
54
  optionalText,
78
- requiredTag = false,
55
+ requiredTag = TEXTAREA_DEFAULTS.requiredTag,
79
56
  requiredText,
80
57
  tagText = null,
81
58
  placeholder,
82
59
  rows,
83
- useWrapper = true,
60
+ useWrapper = TEXTAREA_DEFAULTS.useWrapper,
84
61
  onChange,
85
62
  value,
86
- autoComplete = 'off',
63
+ autoComplete,
64
+ autocomplete,
87
65
  minLength,
88
66
  maxLength,
89
67
  readOnly,
90
68
  skipForwardTestid = false,
91
- inputSize = 'medium',
69
+ inputSize = TEXTAREA_DEFAULTS.inputSize,
92
70
  strings,
93
71
  ...props
94
72
  }: IPktTextarea,
@@ -161,7 +139,7 @@ export const PktTextarea = forwardRef(
161
139
  rows={rows}
162
140
  aria-labelledby={labelledBy}
163
141
  aria-invalid={hasError}
164
- aria-errormessage={hasError ? `${id}-error` : undefined}
142
+ aria-errormessage={hasError ? `${inputId}-error` : undefined}
165
143
  aria-describedby={describedByIds({
166
144
  id: inputId,
167
145
  hasHelptext: !!helptext,
@@ -171,7 +149,7 @@ export const PktTextarea = forwardRef(
171
149
  {...props}
172
150
  onChange={handleChange}
173
151
  value={value}
174
- autoComplete={autoComplete}
152
+ autoComplete={autoComplete ?? autocomplete ?? TEXTAREA_DEFAULTS.autoComplete}
175
153
  minLength={minLength}
176
154
  maxLength={maxLength}
177
155
  readOnly={readOnly}