@oslokommune/punkt-react 19.17.1 → 19.18.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 +15 -0
- package/dist/components/calendar/CalendarGrid.d.ts +1 -1
- package/dist/components/calendar/CalendarNav.d.ts +1 -1
- package/dist/components/combobox/ComboboxInput.d.ts +1 -1
- package/dist/components/combobox/ComboboxTags.d.ts +2 -2
- package/dist/components/combobox/Listbox.d.ts +1 -1
- package/dist/components/datepicker/DateTags.d.ts +1 -1
- package/dist/components/datepicker/DatepickerInputs.d.ts +1 -1
- package/dist/components/datepicker/DatepickerPopup.d.ts +1 -1
- package/dist/components/fileupload/Subcomponents.d.ts +6 -6
- package/dist/components/header-menu/HeaderMenu.d.ts +1 -1
- package/dist/components/icon/Icon.js +7 -1
- package/dist/components/index.d.ts +1 -0
- package/dist/components/linkcard/LinkCard.d.ts +1 -1
- package/dist/components/stepper/Step.d.ts +1 -1
- package/dist/components/strings/PktStringsProvider.d.ts +1 -1
- package/dist/components/table/Table.d.ts +1 -1
- package/dist/components/table/TableBody.d.ts +1 -1
- package/dist/components/table/TableDataCell.d.ts +1 -1
- package/dist/components/table/TableHeader.d.ts +1 -1
- package/dist/components/table/TableHeaderCell.d.ts +1 -1
- package/dist/components/table/TableRow.d.ts +1 -1
- package/dist/components/textarea/Textarea.d.ts +4 -29
- package/dist/components/textarea/Textarea.js +62 -61
- package/dist/punkt-react.cjs +1 -1
- package/dist/shared-types/index.d.ts +2 -0
- package/dist/shared-types/textarea.d.ts +67 -0
- package/dist/shared-types/textarea.js +16 -0
- package/package.json +4 -4
- package/src/components/icon/Icon.test.tsx +22 -0
- package/src/components/icon/Icon.tsx +7 -1
- package/src/components/index.ts +1 -0
- package/src/components/textarea/Textarea.test.tsx +42 -1
- package/src/components/textarea/Textarea.tsx +16 -38
|
@@ -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.
|
|
3
|
+
"version": "19.18.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",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"@eslint/js": "^10.0.1",
|
|
44
44
|
"@oslokommune/punkt-assets": "^19.14.2",
|
|
45
45
|
"@oslokommune/punkt-css": "^19.16.2",
|
|
46
|
-
"@testing-library/jest-dom": "^
|
|
46
|
+
"@testing-library/jest-dom": "^7.0.1",
|
|
47
47
|
"@testing-library/react": "^16.3.2",
|
|
48
48
|
"@testing-library/user-event": "^14.6.1",
|
|
49
49
|
"@types/jest-axe": "^3.5.9",
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"eslint-plugin-react-hooks": "^7.1.1",
|
|
59
59
|
"eslint-plugin-simple-import-sort": "^13.0.0",
|
|
60
60
|
"globals": "^17.6.0",
|
|
61
|
-
"jest-axe": "^
|
|
61
|
+
"jest-axe": "^11.0.0",
|
|
62
62
|
"jsdom": "^29.1.1",
|
|
63
63
|
"prettier": "^3.8.4",
|
|
64
64
|
"react-hook-form": "^7.79.0",
|
|
@@ -102,5 +102,5 @@
|
|
|
102
102
|
"url": "https://github.com/oslokommune/punkt/issues"
|
|
103
103
|
},
|
|
104
104
|
"license": "MIT",
|
|
105
|
-
"gitHead": "
|
|
105
|
+
"gitHead": "7c8508f96a754c830bc794977065f4c162f45240"
|
|
106
106
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import '@testing-library/jest-dom'
|
|
2
|
+
import { vi } from 'vitest'
|
|
2
3
|
|
|
3
4
|
import { render, screen, waitFor } from '../../utils/test-utils'
|
|
4
5
|
import { PktIcon } from './Icon'
|
|
@@ -109,4 +110,25 @@ describe('PktIcon', () => {
|
|
|
109
110
|
expect(svg).toHaveAttribute('aria-label', 'chevron-right')
|
|
110
111
|
})
|
|
111
112
|
})
|
|
113
|
+
|
|
114
|
+
describe('Restricted storage', () => {
|
|
115
|
+
test('loads when reading sessionStorage throws', async () => {
|
|
116
|
+
const original = Object.getOwnPropertyDescriptor(globalThis, 'sessionStorage')
|
|
117
|
+
Object.defineProperty(globalThis, 'sessionStorage', {
|
|
118
|
+
configurable: true,
|
|
119
|
+
get() {
|
|
120
|
+
throw new DOMException('Access is denied for this document.', 'SecurityError')
|
|
121
|
+
},
|
|
122
|
+
})
|
|
123
|
+
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {})
|
|
124
|
+
vi.resetModules()
|
|
125
|
+
try {
|
|
126
|
+
await expect(import('./Icon')).resolves.toHaveProperty('PktIcon')
|
|
127
|
+
} finally {
|
|
128
|
+
if (original) Object.defineProperty(globalThis, 'sessionStorage', original)
|
|
129
|
+
else delete (globalThis as { sessionStorage?: Storage }).sessionStorage
|
|
130
|
+
warn.mockRestore()
|
|
131
|
+
}
|
|
132
|
+
})
|
|
133
|
+
})
|
|
112
134
|
})
|
|
@@ -22,7 +22,13 @@ const dlCache: { [key: string]: Promise<string> } = {}
|
|
|
22
22
|
const MAX_RETRIES = 2
|
|
23
23
|
const RETRY_DELAY = 1500
|
|
24
24
|
|
|
25
|
-
const isSessionStorageAvailable =
|
|
25
|
+
const isSessionStorageAvailable = (() => {
|
|
26
|
+
try {
|
|
27
|
+
return typeof Storage !== 'undefined' && typeof sessionStorage !== 'undefined'
|
|
28
|
+
} catch {
|
|
29
|
+
return false
|
|
30
|
+
}
|
|
31
|
+
})()
|
|
26
32
|
|
|
27
33
|
const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect
|
|
28
34
|
|
package/src/components/index.ts
CHANGED
|
@@ -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 =
|
|
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 {
|
|
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
|
|
19
|
+
extends
|
|
20
|
+
Omit<IPktTextareaBase, 'helptext' | 'helptextDropdown' | 'errorMessage'>,
|
|
21
|
+
Omit<TextareaHTMLAttributes<HTMLTextAreaElement>, keyof IPktTextareaBase> {
|
|
21
22
|
id: string
|
|
22
|
-
|
|
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
|
-
|
|
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 =
|
|
45
|
+
hasError = TEXTAREA_DEFAULTS.hasError,
|
|
69
46
|
helptext,
|
|
70
47
|
helptextDropdown,
|
|
71
48
|
helptextDropdownButton,
|
|
72
49
|
inline,
|
|
73
|
-
fullwidth =
|
|
50
|
+
fullwidth = TEXTAREA_DEFAULTS.fullwidth,
|
|
74
51
|
label,
|
|
75
52
|
name,
|
|
76
|
-
optionalTag =
|
|
53
|
+
optionalTag = TEXTAREA_DEFAULTS.optionalTag,
|
|
77
54
|
optionalText,
|
|
78
|
-
requiredTag =
|
|
55
|
+
requiredTag = TEXTAREA_DEFAULTS.requiredTag,
|
|
79
56
|
requiredText,
|
|
80
57
|
tagText = null,
|
|
81
58
|
placeholder,
|
|
82
59
|
rows,
|
|
83
|
-
useWrapper =
|
|
60
|
+
useWrapper = TEXTAREA_DEFAULTS.useWrapper,
|
|
84
61
|
onChange,
|
|
85
62
|
value,
|
|
86
|
-
autoComplete
|
|
63
|
+
autoComplete,
|
|
64
|
+
autocomplete,
|
|
87
65
|
minLength,
|
|
88
66
|
maxLength,
|
|
89
67
|
readOnly,
|
|
90
68
|
skipForwardTestid = false,
|
|
91
|
-
inputSize =
|
|
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 ? `${
|
|
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}
|