@oslokommune/punkt-react 18.7.2 → 18.9.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.
- package/CHANGELOG.md +40 -0
- package/dist/components/combobox/types.d.ts +2 -0
- package/dist/components/formAttribute.test.d.ts +1 -0
- package/dist/components/timepicker/useTimepickerState.d.ts +1 -0
- package/dist/punkt-react.cjs +1 -1
- package/dist/punkt-react.js +1660 -1643
- package/dist/shared-types/fileupload.d.ts +2 -1
- package/package.json +3 -3
- package/src/components/checkbox/Checkbox.tsx +26 -13
- package/src/components/combobox/Combobox.tsx +1 -0
- package/src/components/combobox/types.ts +2 -0
- package/src/components/combobox/useComboboxState.ts +8 -5
- package/src/components/fileupload/DropZone.tsx +7 -1
- package/src/components/fileupload/FileUpload.tsx +1 -0
- package/src/components/formAttribute.test.tsx +96 -0
- package/src/components/radio/RadioButton.tsx +22 -19
- package/src/components/timepicker/Timepicker.tsx +1 -0
- package/src/components/timepicker/useTimepickerState.ts +14 -14
|
@@ -61,6 +61,7 @@ export interface IFilesChangedDetail {
|
|
|
61
61
|
export interface IPktFileUploadBase extends IFormFieldCommonProps<'forms' | 'fileupload'> {
|
|
62
62
|
/** Field name. Used for native input (`form`) or hidden ID inputs (`custom`). */
|
|
63
63
|
name: string;
|
|
64
|
+
form?: string;
|
|
64
65
|
required?: boolean;
|
|
65
66
|
value?: IFileItem[];
|
|
66
67
|
defaultValue?: IFileItem[];
|
|
@@ -93,7 +94,7 @@ export interface IPktFileUploadBase extends IFormFieldCommonProps<'forms' | 'fil
|
|
|
93
94
|
truncateTail?: number;
|
|
94
95
|
}
|
|
95
96
|
/** Documented props for typed component specs — subset of base + docs-only demo props. */
|
|
96
|
-
export type IFileUploadSpecProps = Pick<IPktFileUploadBase, TFormFieldCommonSpecKeys | 'name' | 'required' | 'value' | 'defaultValue' | 'onFilesChanged' | 'uploadStrategy' | 'multiple' | 'itemRenderer' | 'allowedFormats' | 'formatErrorMessage' | 'maxFileSize' | 'onFileValidation' | 'onFileValidate' | 'sizeErrorMessage' | 'addCommentsEnabled' | 'enableImagePreview' | 'extraOperations' | 'fullwidth' | 'onFileUploadRequested' | 'onTransferCancelled' | 'renameFilesEnabled' | 'transfers' | 'truncateTail'> & {
|
|
97
|
+
export type IFileUploadSpecProps = Pick<IPktFileUploadBase, TFormFieldCommonSpecKeys | 'name' | 'form' | 'required' | 'value' | 'defaultValue' | 'onFilesChanged' | 'uploadStrategy' | 'multiple' | 'itemRenderer' | 'allowedFormats' | 'formatErrorMessage' | 'maxFileSize' | 'onFileValidation' | 'onFileValidate' | 'sizeErrorMessage' | 'addCommentsEnabled' | 'enableImagePreview' | 'extraOperations' | 'fullwidth' | 'onFileUploadRequested' | 'onTransferCancelled' | 'renameFilesEnabled' | 'transfers' | 'truncateTail'> & {
|
|
97
98
|
previewUploadIntervalMs?: number;
|
|
98
99
|
previewSimulateUploadError?: boolean;
|
|
99
100
|
previewUploadStatus?: TPreviewUploadStatus;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oslokommune/punkt-react",
|
|
3
|
-
"version": "18.
|
|
3
|
+
"version": "18.9.0",
|
|
4
4
|
"description": "React komponentbibliotek til Punkt, et designsystem laget av Oslo Origo",
|
|
5
5
|
"homepage": "https://punkt.oslo.kommune.no",
|
|
6
6
|
"author": "Team Designsystem, Oslo Origo",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"@eslint/eslintrc": "^3.3.5",
|
|
41
41
|
"@eslint/js": "^10.0.1",
|
|
42
42
|
"@oslokommune/punkt-assets": "^18.7.1",
|
|
43
|
-
"@oslokommune/punkt-css": "^18.
|
|
43
|
+
"@oslokommune/punkt-css": "^18.8.0",
|
|
44
44
|
"@testing-library/jest-dom": "^6.9.1",
|
|
45
45
|
"@testing-library/react": "^16.3.2",
|
|
46
46
|
"@testing-library/user-event": "^14.6.1",
|
|
@@ -100,5 +100,5 @@
|
|
|
100
100
|
"url": "https://github.com/oslokommune/punkt/issues"
|
|
101
101
|
},
|
|
102
102
|
"license": "MIT",
|
|
103
|
-
"gitHead": "
|
|
103
|
+
"gitHead": "a8576c656211eb84b7689fc0b9795e3f10d8e1c8"
|
|
104
104
|
}
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
useRef,
|
|
10
10
|
} from 'react'
|
|
11
11
|
import { usePktStrings } from '../../hooks/usePktStrings'
|
|
12
|
+
import { useGeneratedId } from '../../hooks/useGeneratedId'
|
|
12
13
|
import type { IPktStringsProps } from 'shared-strings'
|
|
13
14
|
|
|
14
15
|
export interface IPktCheckbox extends InputHTMLAttributes<HTMLInputElement>, IPktStringsProps<'forms'> {
|
|
@@ -38,7 +39,7 @@ export interface IPktCheckbox extends InputHTMLAttributes<HTMLInputElement>, IPk
|
|
|
38
39
|
export const PktCheckbox = forwardRef(
|
|
39
40
|
(
|
|
40
41
|
{
|
|
41
|
-
id,
|
|
42
|
+
id: idProp,
|
|
42
43
|
hasTile = false,
|
|
43
44
|
disabled = false,
|
|
44
45
|
label,
|
|
@@ -57,11 +58,13 @@ export const PktCheckbox = forwardRef(
|
|
|
57
58
|
requiredText,
|
|
58
59
|
strings,
|
|
59
60
|
tagText,
|
|
61
|
+
'aria-describedby': ariaDescribedbyProp,
|
|
60
62
|
...props
|
|
61
63
|
}: IPktCheckbox,
|
|
62
64
|
ref: ForwardedRef<HTMLInputElement>,
|
|
63
65
|
): ReactElement => {
|
|
64
66
|
const s = usePktStrings(['forms'], strings)
|
|
67
|
+
const id = useGeneratedId(idProp)
|
|
65
68
|
const internalRef = useRef<HTMLInputElement>(null)
|
|
66
69
|
|
|
67
70
|
useEffect(() => {
|
|
@@ -112,15 +115,28 @@ export const PktCheckbox = forwardRef(
|
|
|
112
115
|
)
|
|
113
116
|
}
|
|
114
117
|
|
|
118
|
+
const labelId = `${id}-check-label`
|
|
119
|
+
const helptextId = `${id}-check-helptext`
|
|
120
|
+
const describedBy =
|
|
121
|
+
[checkHelptext ? helptextId : undefined, ariaDescribedbyProp].filter(Boolean).join(' ') || undefined
|
|
122
|
+
|
|
123
|
+
const renderLabel = () => (
|
|
124
|
+
<label className={labelClasses} htmlFor={id}>
|
|
125
|
+
<span id={labelId}>
|
|
126
|
+
{label} {renderTags()}
|
|
127
|
+
</span>
|
|
128
|
+
{checkHelptext && (
|
|
129
|
+
<div id={helptextId} className="pkt-input-check__input-helptext">
|
|
130
|
+
{checkHelptext}
|
|
131
|
+
</div>
|
|
132
|
+
)}
|
|
133
|
+
</label>
|
|
134
|
+
)
|
|
135
|
+
|
|
115
136
|
return (
|
|
116
137
|
<div className={classes}>
|
|
117
138
|
<div className={inputTileClasses}>
|
|
118
|
-
{labelPosition === 'left' && (
|
|
119
|
-
<label className={labelClasses} htmlFor={id}>
|
|
120
|
-
{label} {renderTags()}
|
|
121
|
-
{checkHelptext && <div className="pkt-input-check__input-helptext">{checkHelptext}</div>}
|
|
122
|
-
</label>
|
|
123
|
-
)}
|
|
139
|
+
{labelPosition === 'left' && renderLabel()}
|
|
124
140
|
<input
|
|
125
141
|
role={isSwitch ? 'switch' : 'checkbox'}
|
|
126
142
|
ref={internalRef}
|
|
@@ -128,15 +144,12 @@ export const PktCheckbox = forwardRef(
|
|
|
128
144
|
type="checkbox"
|
|
129
145
|
id={id}
|
|
130
146
|
disabled={disabled}
|
|
147
|
+
aria-labelledby={label ? labelId : undefined}
|
|
148
|
+
aria-describedby={describedBy}
|
|
131
149
|
{...(checked !== undefined ? { checked } : { defaultChecked })}
|
|
132
150
|
{...props}
|
|
133
151
|
/>
|
|
134
|
-
{labelPosition === 'right' && (
|
|
135
|
-
<label className={labelClasses} htmlFor={id}>
|
|
136
|
-
{label} {renderTags()}
|
|
137
|
-
{checkHelptext && <div className="pkt-input-check__input-helptext">{checkHelptext}</div>}
|
|
138
|
-
</label>
|
|
139
|
-
)}
|
|
152
|
+
{labelPosition === 'right' && renderLabel()}
|
|
140
153
|
</div>
|
|
141
154
|
</div>
|
|
142
155
|
)
|
|
@@ -33,6 +33,7 @@ export interface IPktCombobox extends IPktStringsProps<'combobox' | 'listbox' |
|
|
|
33
33
|
|
|
34
34
|
// Form
|
|
35
35
|
name?: string
|
|
36
|
+
form?: string
|
|
36
37
|
id?: string
|
|
37
38
|
disabled?: boolean
|
|
38
39
|
required?: boolean
|
|
@@ -122,6 +123,7 @@ export interface IComboboxState {
|
|
|
122
123
|
inline: boolean
|
|
123
124
|
inputSize: 'small' | 'medium' | 'xsmall'
|
|
124
125
|
name?: string
|
|
126
|
+
form?: string
|
|
125
127
|
className?: string
|
|
126
128
|
|
|
127
129
|
// Derived state
|
|
@@ -34,6 +34,7 @@ import {
|
|
|
34
34
|
import type { IPktCombobox, IComboboxState } from './types'
|
|
35
35
|
import { formatString } from 'shared-strings'
|
|
36
36
|
import { usePktStrings } from '../../hooks/usePktStrings'
|
|
37
|
+
import { useOwnerForm } from '../../hooks/useOwnerForm'
|
|
37
38
|
|
|
38
39
|
// Options sync helper (React-specific: immutable, returns new array)
|
|
39
40
|
function syncOptionsWithValues(options: IPktComboboxOption[], values: string[]): IPktComboboxOption[] {
|
|
@@ -80,6 +81,7 @@ export function useComboboxState(props: IPktCombobox, ref: React.ForwardedRef<HT
|
|
|
80
81
|
counter,
|
|
81
82
|
inputSize = 'medium',
|
|
82
83
|
name,
|
|
84
|
+
form,
|
|
83
85
|
className,
|
|
84
86
|
onChange,
|
|
85
87
|
onValueChange,
|
|
@@ -98,6 +100,7 @@ export function useComboboxState(props: IPktCombobox, ref: React.ForwardedRef<HT
|
|
|
98
100
|
const triggerRef = useRef<HTMLDivElement>(null)
|
|
99
101
|
const listboxRef = useRef<HTMLDivElement>(null)
|
|
100
102
|
const wrapperRef = useRef<HTMLDivElement>(null)
|
|
103
|
+
const ownerForm = useOwnerForm(wrapperRef, form)
|
|
101
104
|
|
|
102
105
|
// Focus the appropriate trigger: text input for editable, combobox div for select-only
|
|
103
106
|
const focusTrigger = useCallback(() => {
|
|
@@ -1036,8 +1039,7 @@ export function useComboboxState(props: IPktCombobox, ref: React.ForwardedRef<HT
|
|
|
1036
1039
|
|
|
1037
1040
|
// Form reset: listen for the parent <form>'s reset event and restore initial values
|
|
1038
1041
|
useEffect(() => {
|
|
1039
|
-
|
|
1040
|
-
if (!form) return
|
|
1042
|
+
if (!ownerForm) return
|
|
1041
1043
|
|
|
1042
1044
|
const handleReset = () => {
|
|
1043
1045
|
// Use setTimeout so the reset event finishes before we update state
|
|
@@ -1055,9 +1057,9 @@ export function useComboboxState(props: IPktCombobox, ref: React.ForwardedRef<HT
|
|
|
1055
1057
|
}, 0)
|
|
1056
1058
|
}
|
|
1057
1059
|
|
|
1058
|
-
|
|
1059
|
-
return () =>
|
|
1060
|
-
}, [multiple])
|
|
1060
|
+
ownerForm.addEventListener('reset', handleReset)
|
|
1061
|
+
return () => ownerForm.removeEventListener('reset', handleReset)
|
|
1062
|
+
}, [multiple, ownerForm])
|
|
1061
1063
|
|
|
1062
1064
|
// Expose value getter/setter on ref for RHF register() compatibility.
|
|
1063
1065
|
// RHF reads ref.value via getFieldValue(field._f) — we read directly from the
|
|
@@ -1152,6 +1154,7 @@ export function useComboboxState(props: IPktCombobox, ref: React.ForwardedRef<HT
|
|
|
1152
1154
|
inline,
|
|
1153
1155
|
inputSize,
|
|
1154
1156
|
name,
|
|
1157
|
+
form,
|
|
1155
1158
|
className,
|
|
1156
1159
|
|
|
1157
1160
|
// Derived
|
|
@@ -216,7 +216,13 @@ export const DropZone = forwardRef<HTMLInputElement, IDropZoneProps>(
|
|
|
216
216
|
{uploadStrategy === 'custom' && (
|
|
217
217
|
<>
|
|
218
218
|
{value?.map((fileItem) => (
|
|
219
|
-
<input
|
|
219
|
+
<input
|
|
220
|
+
key={fileItem.fileId}
|
|
221
|
+
type="hidden"
|
|
222
|
+
name={name}
|
|
223
|
+
form={inputProps.form}
|
|
224
|
+
value={fileItem.fileId}
|
|
225
|
+
/>
|
|
220
226
|
))}
|
|
221
227
|
</>
|
|
222
228
|
)}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { render } from '@testing-library/react'
|
|
2
|
+
import type { ReactNode } from 'react'
|
|
3
|
+
import { PktTextinput } from './textinput/Textinput'
|
|
4
|
+
import { PktTextarea } from './textarea/Textarea'
|
|
5
|
+
import { PktCheckbox } from './checkbox/Checkbox'
|
|
6
|
+
import { PktRadioButton } from './radio/RadioButton'
|
|
7
|
+
import { PktSelect } from './select/Select'
|
|
8
|
+
import { PktCombobox } from './combobox/Combobox'
|
|
9
|
+
import { PktDatepicker } from './datepicker/Datepicker'
|
|
10
|
+
import { PktTimepicker } from './timepicker/Timepicker'
|
|
11
|
+
import { PktFileUpload } from './fileupload/FileUpload'
|
|
12
|
+
|
|
13
|
+
const fields = (form?: string): ReactNode => (
|
|
14
|
+
<>
|
|
15
|
+
<PktTextinput id="ti" name="ti" label="Tekst" form={form} defaultValue="a" />
|
|
16
|
+
<PktTextarea id="ta" name="ta" label="Tekstområde" form={form} defaultValue="b" />
|
|
17
|
+
<PktCheckbox id="cb" name="cb" label="Avkryssing" form={form} value="on" defaultChecked />
|
|
18
|
+
<PktRadioButton id="rb" name="rb" label="Radio" form={form} value="r1" defaultChecked />
|
|
19
|
+
<PktSelect id="se" name="se" label="Nedtrekk" form={form} defaultValue="s1">
|
|
20
|
+
<option value="s1">s1</option>
|
|
21
|
+
</PktSelect>
|
|
22
|
+
<PktCombobox
|
|
23
|
+
id="co"
|
|
24
|
+
name="co"
|
|
25
|
+
label="Kombiboks"
|
|
26
|
+
form={form}
|
|
27
|
+
value="c1"
|
|
28
|
+
options={[{ value: 'c1', label: 'c1' }]}
|
|
29
|
+
/>
|
|
30
|
+
<PktDatepicker id="dp" name="dp" label="Dato" form={form} value="2026-01-01" />
|
|
31
|
+
<PktTimepicker id="tp" name="tp" label="Tid" form={form} value="13:45" />
|
|
32
|
+
<PktFileUpload
|
|
33
|
+
id="fu"
|
|
34
|
+
name="fu"
|
|
35
|
+
label="Fil"
|
|
36
|
+
form={form}
|
|
37
|
+
uploadStrategy="custom"
|
|
38
|
+
transfers={[]}
|
|
39
|
+
onFileUploadRequested={() => {}}
|
|
40
|
+
value={[
|
|
41
|
+
{
|
|
42
|
+
fileId: 'f1',
|
|
43
|
+
file: new File(['a'], 'a.txt'),
|
|
44
|
+
attributes: { targetFilename: 'a.txt' },
|
|
45
|
+
},
|
|
46
|
+
]}
|
|
47
|
+
/>
|
|
48
|
+
</>
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
const expected = {
|
|
52
|
+
ti: 'a',
|
|
53
|
+
ta: 'b',
|
|
54
|
+
cb: 'on',
|
|
55
|
+
rb: 'r1',
|
|
56
|
+
se: 's1',
|
|
57
|
+
co: 'c1',
|
|
58
|
+
dp: '2026-01-01',
|
|
59
|
+
tp: '13:45',
|
|
60
|
+
fu: 'f1',
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const submitted = (container: HTMLElement) => {
|
|
64
|
+
const data = new FormData(container.querySelector('#skjema') as HTMLFormElement)
|
|
65
|
+
return Object.fromEntries(Object.keys(expected).map((name) => [name, data.get(name)]))
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
describe('form attribute', () => {
|
|
69
|
+
test('submits every field nested inside the form', () => {
|
|
70
|
+
const { container } = render(<form id="skjema">{fields()}</form>)
|
|
71
|
+
|
|
72
|
+
expect(submitted(container)).toEqual(expected)
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
test('submits every field linked to the form with the form attribute', () => {
|
|
76
|
+
const { container } = render(
|
|
77
|
+
<>
|
|
78
|
+
<form id="skjema" />
|
|
79
|
+
{fields('skjema')}
|
|
80
|
+
</>,
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
expect(submitted(container)).toEqual(expected)
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
test('leaves fields out of a form they are not linked to', () => {
|
|
87
|
+
const { container } = render(
|
|
88
|
+
<>
|
|
89
|
+
<form id="skjema" />
|
|
90
|
+
{fields()}
|
|
91
|
+
</>,
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
expect(new FormData(container.querySelector('#skjema') as HTMLFormElement).entries().next().done).toBe(true)
|
|
95
|
+
})
|
|
96
|
+
})
|
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ChangeEventHandler,
|
|
3
|
-
ForwardedRef,
|
|
4
|
-
forwardRef,
|
|
5
|
-
type InputHTMLAttributes,
|
|
6
|
-
ReactElement,
|
|
7
|
-
ReactNode,
|
|
8
|
-
} from 'react'
|
|
1
|
+
import { ChangeEventHandler, ForwardedRef, forwardRef, type InputHTMLAttributes, ReactElement, ReactNode } from 'react'
|
|
9
2
|
import { usePktStrings } from '../../hooks/usePktStrings'
|
|
3
|
+
import { useGeneratedId } from '../../hooks/useGeneratedId'
|
|
10
4
|
import type { IPktStringsProps } from 'shared-strings'
|
|
11
5
|
|
|
12
6
|
export interface IPktRadioButton extends InputHTMLAttributes<HTMLInputElement>, IPktStringsProps<'forms'> {
|
|
@@ -33,7 +27,7 @@ export interface IPktRadioButton extends InputHTMLAttributes<HTMLInputElement>,
|
|
|
33
27
|
export const PktRadioButton = forwardRef(
|
|
34
28
|
(
|
|
35
29
|
{
|
|
36
|
-
id,
|
|
30
|
+
id: idProp,
|
|
37
31
|
name,
|
|
38
32
|
label,
|
|
39
33
|
className,
|
|
@@ -49,11 +43,13 @@ export const PktRadioButton = forwardRef(
|
|
|
49
43
|
requiredText,
|
|
50
44
|
strings,
|
|
51
45
|
tagText,
|
|
46
|
+
'aria-describedby': ariaDescribedbyProp,
|
|
52
47
|
...props
|
|
53
48
|
}: IPktRadioButton,
|
|
54
49
|
ref: ForwardedRef<HTMLInputElement>,
|
|
55
50
|
): ReactElement => {
|
|
56
51
|
const s = usePktStrings(['forms'], strings)
|
|
52
|
+
const id = useGeneratedId(idProp)
|
|
57
53
|
const classes = [className, 'pkt-input-check'].filter(Boolean).join(' ')
|
|
58
54
|
|
|
59
55
|
const inputTileClasses = [
|
|
@@ -82,19 +78,18 @@ export const PktRadioButton = forwardRef(
|
|
|
82
78
|
<>
|
|
83
79
|
{tagText && <span className={tagClasses + ` pkt-tag--gray`}>{tagText}</span>}
|
|
84
80
|
{optionalTag && (
|
|
85
|
-
<span className={tagClasses + ` pkt-tag--blue-light`}>
|
|
86
|
-
{optionalText ?? s.forms.optional}
|
|
87
|
-
</span>
|
|
88
|
-
)}
|
|
89
|
-
{requiredTag && (
|
|
90
|
-
<span className={tagClasses + ` pkt-tag--beige`}>
|
|
91
|
-
{requiredText ?? s.forms.required}
|
|
92
|
-
</span>
|
|
81
|
+
<span className={tagClasses + ` pkt-tag--blue-light`}>{optionalText ?? s.forms.optional}</span>
|
|
93
82
|
)}
|
|
83
|
+
{requiredTag && <span className={tagClasses + ` pkt-tag--beige`}>{requiredText ?? s.forms.required}</span>}
|
|
94
84
|
</>
|
|
95
85
|
)
|
|
96
86
|
}
|
|
97
87
|
|
|
88
|
+
const labelId = `${id}-check-label`
|
|
89
|
+
const helptextId = `${id}-check-helptext`
|
|
90
|
+
const describedBy =
|
|
91
|
+
[checkHelptext ? helptextId : undefined, ariaDescribedbyProp].filter(Boolean).join(' ') || undefined
|
|
92
|
+
|
|
98
93
|
return (
|
|
99
94
|
<div className={classes}>
|
|
100
95
|
<div className={inputTileClasses}>
|
|
@@ -105,12 +100,20 @@ export const PktRadioButton = forwardRef(
|
|
|
105
100
|
name={name}
|
|
106
101
|
disabled={disabled}
|
|
107
102
|
className={inputCheckBoxClasses}
|
|
103
|
+
aria-labelledby={label ? labelId : undefined}
|
|
104
|
+
aria-describedby={describedBy}
|
|
108
105
|
{...(checked !== undefined ? { checked } : { defaultChecked })}
|
|
109
106
|
{...props}
|
|
110
107
|
/>
|
|
111
108
|
<label className={labelClasses} htmlFor={id}>
|
|
112
|
-
|
|
113
|
-
|
|
109
|
+
<span id={labelId}>
|
|
110
|
+
{label} {renderTags()}
|
|
111
|
+
</span>
|
|
112
|
+
{checkHelptext && (
|
|
113
|
+
<div id={helptextId} className="pkt-input-check__input-helptext">
|
|
114
|
+
{checkHelptext}
|
|
115
|
+
</div>
|
|
116
|
+
)}
|
|
114
117
|
</label>
|
|
115
118
|
</div>
|
|
116
119
|
</div>
|
|
@@ -15,6 +15,7 @@ import { isValidTimeString, timeToMinutes } from 'shared-utils/timepicker/time-u
|
|
|
15
15
|
import type { IPktTimepicker } from './types'
|
|
16
16
|
import { TPktInputSize } from 'shared-types/size'
|
|
17
17
|
import { usePktStrings } from '../../hooks/usePktStrings'
|
|
18
|
+
import { useOwnerForm } from '../../hooks/useOwnerForm'
|
|
18
19
|
import { formatString, type TPktStrings } from 'shared-strings'
|
|
19
20
|
|
|
20
21
|
/**
|
|
@@ -117,6 +118,7 @@ export function useTimepickerState(props: IPktTimepicker, ref: React.ForwardedRe
|
|
|
117
118
|
stepArrows = false,
|
|
118
119
|
fullwidth = false,
|
|
119
120
|
name,
|
|
121
|
+
form,
|
|
120
122
|
disabled = false,
|
|
121
123
|
required = false,
|
|
122
124
|
helptext,
|
|
@@ -196,6 +198,7 @@ export function useTimepickerState(props: IPktTimepicker, ref: React.ForwardedRe
|
|
|
196
198
|
const popupRef = useRef<HTMLDivElement>(null)
|
|
197
199
|
const containerRef = useRef<HTMLDivElement | null>(null)
|
|
198
200
|
const changeInputRef = useRef<HTMLInputElement>(null)
|
|
201
|
+
const ownerForm = useOwnerForm(containerRef, form)
|
|
199
202
|
|
|
200
203
|
const hoursDigitCountRef = useRef(0)
|
|
201
204
|
const hoursFirstDigitRef = useRef(-1)
|
|
@@ -284,15 +287,13 @@ export function useTimepickerState(props: IPktTimepicker, ref: React.ForwardedRe
|
|
|
284
287
|
}, [syncValueFromDisplay, required, min, max, step, catalog.validation])
|
|
285
288
|
|
|
286
289
|
useEffect(() => {
|
|
287
|
-
|
|
288
|
-
const form = root?.closest('form')
|
|
289
|
-
if (!form) return
|
|
290
|
+
if (!ownerForm) return
|
|
290
291
|
|
|
291
292
|
const isSubmitActivator = (target: EventTarget | null) => {
|
|
292
293
|
const el = target as HTMLElement | null
|
|
293
|
-
if (!el || !
|
|
294
|
+
if (!el || !ownerForm.contains(el)) return false
|
|
294
295
|
const control = el.closest('button, input[type="submit"], input[type="image"]')
|
|
295
|
-
if (!control || !
|
|
296
|
+
if (!control || !ownerForm.contains(control)) return false
|
|
296
297
|
if (control instanceof HTMLButtonElement) {
|
|
297
298
|
return control.type !== 'button' && control.type !== 'reset'
|
|
298
299
|
}
|
|
@@ -304,9 +305,9 @@ export function useTimepickerState(props: IPktTimepicker, ref: React.ForwardedRe
|
|
|
304
305
|
applyNativeConstraintAnchorMessage()
|
|
305
306
|
}
|
|
306
307
|
|
|
307
|
-
|
|
308
|
-
return () =>
|
|
309
|
-
}, [applyNativeConstraintAnchorMessage])
|
|
308
|
+
ownerForm.addEventListener('pointerdown', onPointerDownCapture, true)
|
|
309
|
+
return () => ownerForm.removeEventListener('pointerdown', onPointerDownCapture, true)
|
|
310
|
+
}, [applyNativeConstraintAnchorMessage, ownerForm])
|
|
310
311
|
|
|
311
312
|
useEffect(() => {
|
|
312
313
|
if (changeInputRef.current) {
|
|
@@ -749,9 +750,7 @@ export function useTimepickerState(props: IPktTimepicker, ref: React.ForwardedRe
|
|
|
749
750
|
)
|
|
750
751
|
|
|
751
752
|
useEffect(() => {
|
|
752
|
-
|
|
753
|
-
const form = root?.closest('form')
|
|
754
|
-
if (!form) return
|
|
753
|
+
if (!ownerForm) return
|
|
755
754
|
|
|
756
755
|
const handleReset = () => {
|
|
757
756
|
window.setTimeout(() => {
|
|
@@ -770,9 +769,9 @@ export function useTimepickerState(props: IPktTimepicker, ref: React.ForwardedRe
|
|
|
770
769
|
}, 0)
|
|
771
770
|
}
|
|
772
771
|
|
|
773
|
-
|
|
774
|
-
return () =>
|
|
775
|
-
}, [isControlled, setHours, setMinutes])
|
|
772
|
+
ownerForm.addEventListener('reset', handleReset)
|
|
773
|
+
return () => ownerForm.removeEventListener('reset', handleReset)
|
|
774
|
+
}, [isControlled, setHours, setMinutes, ownerForm])
|
|
776
775
|
|
|
777
776
|
const outerClasses = [
|
|
778
777
|
'pkt-timepicker',
|
|
@@ -820,6 +819,7 @@ export function useTimepickerState(props: IPktTimepicker, ref: React.ForwardedRe
|
|
|
820
819
|
popupId,
|
|
821
820
|
hiddenInputId,
|
|
822
821
|
name: name ?? id,
|
|
822
|
+
form,
|
|
823
823
|
isOpen,
|
|
824
824
|
hourOptions,
|
|
825
825
|
minuteOptions,
|