@oslokommune/punkt-react 19.2.0 → 19.3.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 +13 -0
- package/dist/components/card/Card.d.ts +2 -1
- package/dist/components/checkbox/Checkbox.d.ts +2 -20
- package/dist/components/datepicker/types.d.ts +1 -1
- package/dist/components/fileupload/extensions/Comments.d.ts +2 -1
- package/dist/components/fileupload/extensions/Remove.d.ts +2 -1
- package/dist/components/fileupload/extensions/Rename.d.ts +2 -1
- package/dist/components/fileupload/hooks/index.d.ts +1 -0
- package/dist/components/fileupload/hooks/useImageObjectUrl.d.ts +1 -0
- package/dist/components/fileupload/hooks.d.ts +1 -0
- package/dist/components/fileupload/types.d.ts +2 -0
- package/dist/components/header-menu/HeaderMenu.d.ts +3 -2
- package/dist/components/messagebox/Messagebox.d.ts +2 -1
- package/dist/components/modal/Modal.d.ts +2 -1
- package/dist/punkt-react.cjs +1 -1
- package/dist/punkt-react.js +1991 -1953
- package/dist/shared-strings/nb.d.ts +34 -0
- package/dist/shared-types/checkbox.d.ts +52 -0
- package/dist/shared-types/index.d.ts +2 -0
- package/package.json +2 -2
- package/src/components/alert/Alert.test.tsx +5 -5
- package/src/components/alert/Alert.tsx +2 -4
- package/src/components/breadcrumbs/Breadcrumbs.tsx +15 -12
- package/src/components/calendar/Calendar.core.test.tsx +22 -16
- package/src/components/calendar/CalendarNav.tsx +11 -6
- package/src/components/calendar/useCalendarState.ts +42 -55
- package/src/components/card/Card.tsx +17 -5
- package/src/components/checkbox/Checkbox.tsx +11 -26
- package/src/components/combobox/ComboboxTags.tsx +3 -3
- package/src/components/combobox/Listbox.tsx +7 -5
- package/src/components/combobox/useComboboxState.ts +22 -18
- package/src/components/consent/Consent.tsx +4 -1
- package/src/components/datepicker/DatepickerInputs.tsx +3 -9
- package/src/components/datepicker/types.ts +1 -1
- package/src/components/datepicker/useDatepickerState.ts +22 -17
- package/src/components/fileupload/DropZone.tsx +10 -10
- package/src/components/fileupload/FileUpload.tsx +9 -14
- package/src/components/fileupload/Subcomponents.tsx +78 -84
- package/src/components/fileupload/extensions/Comments.tsx +56 -50
- package/src/components/fileupload/extensions/Remove.tsx +8 -3
- package/src/components/fileupload/extensions/Rename.tsx +12 -8
- package/src/components/fileupload/hooks/index.ts +1 -0
- package/src/components/fileupload/hooks/useImageObjectUrl.ts +15 -0
- package/src/components/fileupload/hooks/useOperationState.ts +9 -16
- package/src/components/fileupload/hooks.ts +1 -0
- package/src/components/fileupload/types.ts +7 -1
- package/src/components/formAttribute.test.tsx +1 -0
- package/src/components/header/HeaderGlobal.tsx +8 -2
- package/src/components/header/HeaderService.test.tsx +5 -2
- package/src/components/header/HeaderService.tsx +5 -5
- package/src/components/header-menu/HeaderMenu.tsx +8 -3
- package/src/components/headerUserMenu/UserMenu.tsx +3 -2
- package/src/components/inputwrapper/InputWrapper.tsx +20 -27
- package/src/components/loader/Loader.tsx +12 -9
- package/src/components/messagebox/Messagebox.tsx +6 -2
- package/src/components/modal/Modal.tsx +13 -9
- package/src/components/searchinput/SearchInput.tsx +10 -6
- package/src/components/tabs/Tabs.test.tsx +1 -1
- package/src/components/tabs/Tabs.tsx +30 -35
- package/src/components/tag/Tag.tsx +7 -6
- package/src/components/textarea/Textarea.test.tsx +9 -0
- package/src/components/textarea/Textarea.tsx +6 -10
- package/src/components/textinput/Textinput.tsx +3 -9
- package/src/components/timepicker/useTimepickerState.ts +25 -21
|
@@ -13,11 +13,11 @@ interface IComboboxTagsProps {
|
|
|
13
13
|
|
|
14
14
|
export const ComboboxTags = ({ state, outside = false }: IComboboxTagsProps) => {
|
|
15
15
|
const { values, options, disabled, displayValueAs, handleTagRemove, handleTagKeydown, focusedTagIndex } = state
|
|
16
|
-
const
|
|
16
|
+
const tagElementsRef = useRef<(HTMLButtonElement | null)[]>([])
|
|
17
17
|
|
|
18
18
|
useEffect(() => {
|
|
19
19
|
if (!outside && focusedTagIndex >= 0 && focusedTagIndex < values.length) {
|
|
20
|
-
|
|
20
|
+
tagElementsRef.current[focusedTagIndex]?.focus()
|
|
21
21
|
}
|
|
22
22
|
}, [outside, focusedTagIndex, values.length])
|
|
23
23
|
|
|
@@ -59,7 +59,7 @@ export const ComboboxTags = ({ state, outside = false }: IComboboxTagsProps) =>
|
|
|
59
59
|
>
|
|
60
60
|
<PktTag
|
|
61
61
|
ref={(el: HTMLButtonElement | null) => {
|
|
62
|
-
|
|
62
|
+
tagElementsRef.current[index] = el
|
|
63
63
|
}}
|
|
64
64
|
skin={tagSkinColor || 'blue-dark'}
|
|
65
65
|
closeTag
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
|
|
3
|
+
import { formatString } from 'shared-strings'
|
|
3
4
|
import type { IComboboxState } from './types'
|
|
4
5
|
import { PktIcon } from '../icon/Icon'
|
|
5
6
|
import { usePktStrings } from '../../hooks/usePktStrings'
|
|
7
|
+
import { withStableKeys } from '../../utils/stableKeys'
|
|
6
8
|
|
|
7
9
|
interface IListboxProps {
|
|
8
10
|
state: IComboboxState
|
|
@@ -76,7 +78,7 @@ export const Listbox = ({ state }: IListboxProps) => {
|
|
|
76
78
|
)}
|
|
77
79
|
{showMaxBanner && (
|
|
78
80
|
<div className="pkt-listbox__banner pkt-listbox__banner--maximum-reached">
|
|
79
|
-
{
|
|
81
|
+
{formatString(s.listbox.maxReached, { selected: selectedCount, max: maxlength })}
|
|
80
82
|
</div>
|
|
81
83
|
)}
|
|
82
84
|
|
|
@@ -98,20 +100,20 @@ export const Listbox = ({ state }: IListboxProps) => {
|
|
|
98
100
|
onKeyDown={handleNewOptionKeydown}
|
|
99
101
|
>
|
|
100
102
|
<PktIcon className="pkt-listbox__banner-icon" name="plus-sign" />
|
|
101
|
-
|
|
103
|
+
{formatString(s.listbox.addValue, { value: addValueText })}
|
|
102
104
|
</div>
|
|
103
105
|
)}
|
|
104
106
|
|
|
105
107
|
{options.length === 0 && filteredOptions.length === 0 && !showUserMessage && (
|
|
106
108
|
<div className="pkt-listbox__banner pkt-listbox__banner--empty">
|
|
107
109
|
<PktIcon className="pkt-listbox__banner-icon" name="exclamation-mark-circle" />
|
|
108
|
-
|
|
110
|
+
{s.listbox.empty}
|
|
109
111
|
</div>
|
|
110
112
|
)}
|
|
111
113
|
</div>
|
|
112
114
|
|
|
113
115
|
<ul className="pkt-listbox__options" role="presentation">
|
|
114
|
-
{filteredOptions.map((option, index) => {
|
|
116
|
+
{withStableKeys(filteredOptions, (option) => option.value).map(({ item: option, key }, index) => {
|
|
115
117
|
const optionClasses = [
|
|
116
118
|
'pkt-listbox__option',
|
|
117
119
|
!multiple && option.selected && 'pkt-listbox__option--selected',
|
|
@@ -124,7 +126,7 @@ export const Listbox = ({ state }: IListboxProps) => {
|
|
|
124
126
|
|
|
125
127
|
return (
|
|
126
128
|
<li
|
|
127
|
-
key={
|
|
129
|
+
key={key}
|
|
128
130
|
className={optionClasses}
|
|
129
131
|
onClick={() => handleOptionClick(option.value)}
|
|
130
132
|
onKeyDown={(e) => handleOptionKeydown(e, option.value)}
|
|
@@ -175,12 +175,11 @@ export function useComboboxState(props: IPktCombobox, ref: React.ForwardedRef<HT
|
|
|
175
175
|
// Store initial default values for form reset
|
|
176
176
|
const initialValuesRef = useRef(internalValues)
|
|
177
177
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
}, [value, isControlled, multiple])
|
|
178
|
+
const [prevValue, setPrevValue] = useState(value)
|
|
179
|
+
if (isControlled && value !== prevValue) {
|
|
180
|
+
setPrevValue(value)
|
|
181
|
+
setInternalValues(parseValueToArray(value as string | string[] | null | undefined, multiple))
|
|
182
|
+
}
|
|
184
183
|
|
|
185
184
|
const values = isControlled
|
|
186
185
|
? parseValueToArray(value as string | string[] | null | undefined, multiple)
|
|
@@ -201,7 +200,7 @@ export function useComboboxState(props: IPktCombobox, ref: React.ForwardedRef<HT
|
|
|
201
200
|
const [isOpen, setIsOpen] = useState(false)
|
|
202
201
|
const [searchValue, setSearchValue] = useState('')
|
|
203
202
|
const [inputValue, setInputValue] = useState('')
|
|
204
|
-
const [userInfoMessageKey,
|
|
203
|
+
const [userInfoMessageKey, setUserInfoMessageKey] = useState<TComboboxMessageKey>('')
|
|
205
204
|
const [messageValue, setMessageValue] = useState<string | null>(null)
|
|
206
205
|
const [addValueText, setAddValueText] = useState<string | null>(null)
|
|
207
206
|
const [inputFocus, setInputFocus] = useState(false)
|
|
@@ -282,7 +281,7 @@ export function useComboboxState(props: IPktCombobox, ref: React.ForwardedRef<HT
|
|
|
282
281
|
if (!optValue) return
|
|
283
282
|
if (values.includes(optValue)) return
|
|
284
283
|
if (multiple && isMaxSelectionReached(values.length, maxlength ?? null)) {
|
|
285
|
-
|
|
284
|
+
setUserInfoMessageKey('maxSelected')
|
|
286
285
|
return
|
|
287
286
|
}
|
|
288
287
|
const newValues = multiple ? [...values, optValue] : [optValue]
|
|
@@ -352,7 +351,7 @@ export function useComboboxState(props: IPktCombobox, ref: React.ForwardedRef<HT
|
|
|
352
351
|
}
|
|
353
352
|
if (!multiple) {
|
|
354
353
|
setEditingSingleValue(false)
|
|
355
|
-
|
|
354
|
+
setUserInfoMessageKey('')
|
|
356
355
|
}
|
|
357
356
|
}
|
|
358
357
|
},
|
|
@@ -364,7 +363,7 @@ export function useComboboxState(props: IPktCombobox, ref: React.ForwardedRef<HT
|
|
|
364
363
|
(val: string | null) => {
|
|
365
364
|
if (disabled) return
|
|
366
365
|
|
|
367
|
-
|
|
366
|
+
setUserInfoMessageKey('')
|
|
368
367
|
setAddValueText(null)
|
|
369
368
|
|
|
370
369
|
const valueFromOptions = findOptionByValue(options, val)?.value || null
|
|
@@ -458,7 +457,7 @@ export function useComboboxState(props: IPktCombobox, ref: React.ForwardedRef<HT
|
|
|
458
457
|
setSearchValue(newSearchValue)
|
|
459
458
|
resetInput(shouldResetInput, resultingSingleValue)
|
|
460
459
|
// After resetInput, which clears any stale message in single mode.
|
|
461
|
-
|
|
460
|
+
setUserInfoMessageKey(newUserInfoMessage)
|
|
462
461
|
setMessageValue(newMessageValue)
|
|
463
462
|
|
|
464
463
|
if (!shouldOptionsBeOpen) {
|
|
@@ -489,7 +488,7 @@ export function useComboboxState(props: IPktCombobox, ref: React.ForwardedRef<HT
|
|
|
489
488
|
const closeAndProcessInput = useCallback(() => {
|
|
490
489
|
setInputFocus(false)
|
|
491
490
|
setAddValueText(null)
|
|
492
|
-
|
|
491
|
+
setUserInfoMessageKey('')
|
|
493
492
|
setSearchValue('')
|
|
494
493
|
|
|
495
494
|
if (inputRef.current && inputRef.current.type !== 'hidden') {
|
|
@@ -552,7 +551,7 @@ export function useComboboxState(props: IPktCombobox, ref: React.ForwardedRef<HT
|
|
|
552
551
|
|
|
553
552
|
if (!search) {
|
|
554
553
|
setAddValueText(null)
|
|
555
|
-
|
|
554
|
+
setUserInfoMessageKey('')
|
|
556
555
|
if (!multiple && values[0]) {
|
|
557
556
|
removeSelected(values[0])
|
|
558
557
|
}
|
|
@@ -561,7 +560,7 @@ export function useComboboxState(props: IPktCombobox, ref: React.ForwardedRef<HT
|
|
|
561
560
|
|
|
562
561
|
const result = getSearchInfoMessage(currentInputValue, values, options, allowUserInput)
|
|
563
562
|
setAddValueText(result.addValueText)
|
|
564
|
-
|
|
563
|
+
setUserInfoMessageKey(result.userInfoMessage)
|
|
565
564
|
},
|
|
566
565
|
[values, options, allowUserInput, multiple, removeSelected],
|
|
567
566
|
)
|
|
@@ -645,7 +644,7 @@ export function useComboboxState(props: IPktCombobox, ref: React.ForwardedRef<HT
|
|
|
645
644
|
// Just reset the input and keep the "already selected" message.
|
|
646
645
|
if (input && values.includes(input)) {
|
|
647
646
|
resetInput(true)
|
|
648
|
-
|
|
647
|
+
setUserInfoMessageKey('alreadySelected')
|
|
649
648
|
break
|
|
650
649
|
}
|
|
651
650
|
toggleValue(input)
|
|
@@ -1041,16 +1040,18 @@ export function useComboboxState(props: IPktCombobox, ref: React.ForwardedRef<HT
|
|
|
1041
1040
|
// Form reset: listen for the parent <form>'s reset event and restore initial values
|
|
1042
1041
|
useEffect(() => {
|
|
1043
1042
|
if (!ownerForm) return
|
|
1043
|
+
let resetTimeout: number | undefined
|
|
1044
1044
|
|
|
1045
1045
|
const handleReset = () => {
|
|
1046
1046
|
// Use setTimeout so the reset event finishes before we update state
|
|
1047
|
-
window.
|
|
1047
|
+
window.clearTimeout(resetTimeout)
|
|
1048
|
+
resetTimeout = window.setTimeout(() => {
|
|
1048
1049
|
setInternalValues(initialValuesRef.current)
|
|
1049
1050
|
setUserAddedOptions([])
|
|
1050
1051
|
setInputValue('')
|
|
1051
1052
|
setSearchValue('')
|
|
1052
1053
|
setAddValueText(null)
|
|
1053
|
-
|
|
1054
|
+
setUserInfoMessageKey('')
|
|
1054
1055
|
if (changeInputRef.current) {
|
|
1055
1056
|
const resetVal = multiple ? initialValuesRef.current.join(',') : initialValuesRef.current[0] || ''
|
|
1056
1057
|
changeInputRef.current.value = resetVal
|
|
@@ -1059,7 +1060,10 @@ export function useComboboxState(props: IPktCombobox, ref: React.ForwardedRef<HT
|
|
|
1059
1060
|
}
|
|
1060
1061
|
|
|
1061
1062
|
ownerForm.addEventListener('reset', handleReset)
|
|
1062
|
-
return () =>
|
|
1063
|
+
return () => {
|
|
1064
|
+
ownerForm.removeEventListener('reset', handleReset)
|
|
1065
|
+
window.clearTimeout(resetTimeout)
|
|
1066
|
+
}
|
|
1063
1067
|
}, [multiple, ownerForm])
|
|
1064
1068
|
|
|
1065
1069
|
// Expose value getter/setter on ref for RHF register() compatibility.
|
|
@@ -152,6 +152,7 @@ export const PktConsent = forwardRef<HTMLElement, IPktConsent>(function PktConse
|
|
|
152
152
|
useEffect(() => {
|
|
153
153
|
let cancelled = false
|
|
154
154
|
let cookieEventHandler: CookieEventHandler | undefined
|
|
155
|
+
let emitTimeout: number | undefined
|
|
155
156
|
|
|
156
157
|
const config = configRef.current
|
|
157
158
|
// cookieBanner_* identifiers are defined by the external cookie banner script
|
|
@@ -187,7 +188,8 @@ export const PktConsent = forwardRef<HTMLElement, IPktConsent>(function PktConse
|
|
|
187
188
|
if (cancelled || !hasConsent) return
|
|
188
189
|
|
|
189
190
|
const cookie = banner.cookieConsent.getConsentCookie()
|
|
190
|
-
window.
|
|
191
|
+
window.clearTimeout(emitTimeout)
|
|
192
|
+
emitTimeout = window.setTimeout(() => {
|
|
191
193
|
if (!cancelled) emitConsents({ value: cookie })
|
|
192
194
|
}, 0)
|
|
193
195
|
|
|
@@ -205,6 +207,7 @@ export const PktConsent = forwardRef<HTMLElement, IPktConsent>(function PktConse
|
|
|
205
207
|
|
|
206
208
|
return () => {
|
|
207
209
|
cancelled = true
|
|
210
|
+
window.clearTimeout(emitTimeout)
|
|
208
211
|
if (cookieEventHandler) {
|
|
209
212
|
window.__cookieEvents?.off('CookieManager.setCookie', cookieEventHandler)
|
|
210
213
|
}
|
|
@@ -30,7 +30,7 @@ export const DatepickerInputs = ({ state }: { state: IDatepickerState }) => {
|
|
|
30
30
|
datepickerInputsClasses,
|
|
31
31
|
isInputDisabled,
|
|
32
32
|
inputRef,
|
|
33
|
-
|
|
33
|
+
inputToRef,
|
|
34
34
|
btnRef,
|
|
35
35
|
toggleCalendar,
|
|
36
36
|
handleFocus,
|
|
@@ -58,13 +58,7 @@ export const DatepickerInputs = ({ state }: { state: IDatepickerState }) => {
|
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
const renderCalendarButton = () => (
|
|
61
|
-
<button
|
|
62
|
-
ref={btnRef}
|
|
63
|
-
className={buttonClasses}
|
|
64
|
-
type="button"
|
|
65
|
-
onClick={toggleCalendar}
|
|
66
|
-
disabled={disabled}
|
|
67
|
-
>
|
|
61
|
+
<button ref={btnRef} className={buttonClasses} type="button" onClick={toggleCalendar} disabled={disabled}>
|
|
68
62
|
<PktIcon name="calendar" />
|
|
69
63
|
<span className="pkt-btn__text">{strings.datepicker.openPicker}</span>
|
|
70
64
|
</button>
|
|
@@ -143,7 +137,7 @@ export const DatepickerInputs = ({ state }: { state: IDatepickerState }) => {
|
|
|
143
137
|
</div>
|
|
144
138
|
{!showRangeLabels && <div className="pkt-input-separator">–</div>}
|
|
145
139
|
<input
|
|
146
|
-
ref={
|
|
140
|
+
ref={inputToRef}
|
|
147
141
|
className={inputClasses}
|
|
148
142
|
type={inputType}
|
|
149
143
|
id={`${id}-to`}
|
|
@@ -115,7 +115,7 @@ export interface IDatepickerState {
|
|
|
115
115
|
|
|
116
116
|
// Refs
|
|
117
117
|
inputRef: React.RefObject<HTMLInputElement | null>
|
|
118
|
-
|
|
118
|
+
inputToRef: React.RefObject<HTMLInputElement | null>
|
|
119
119
|
changeInputRef: React.RefObject<HTMLInputElement | null>
|
|
120
120
|
btnRef: React.RefObject<HTMLButtonElement | null>
|
|
121
121
|
wrapperRef: React.RefObject<HTMLDivElement | null>
|
|
@@ -79,24 +79,24 @@ export function useDatepickerState(props: IPktDatepicker, ref: React.ForwardedRe
|
|
|
79
79
|
// Store initial default values for form reset
|
|
80
80
|
const initialValuesRef = useRef(internalValue)
|
|
81
81
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
82
|
+
const [prevValue, setPrevValue] = useState(value)
|
|
83
|
+
if (isControlled && value !== prevValue) {
|
|
84
|
+
setPrevValue(value)
|
|
85
|
+
setInternalValue(normalizeValue(value))
|
|
86
|
+
}
|
|
87
87
|
|
|
88
88
|
// Calendar state
|
|
89
89
|
const [calendarOpen, setCalendarOpen] = useState(calendarOpenProp ?? false)
|
|
90
90
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}
|
|
91
|
+
const [prevCalendarOpenProp, setPrevCalendarOpenProp] = useState(calendarOpenProp)
|
|
92
|
+
if (calendarOpenProp !== prevCalendarOpenProp) {
|
|
93
|
+
setPrevCalendarOpenProp(calendarOpenProp)
|
|
94
|
+
if (calendarOpenProp !== undefined) setCalendarOpen(calendarOpenProp)
|
|
95
|
+
}
|
|
96
96
|
|
|
97
97
|
// Refs
|
|
98
98
|
const inputRef = useRef<HTMLInputElement>(null)
|
|
99
|
-
const
|
|
99
|
+
const inputToRef = useRef<HTMLInputElement>(null)
|
|
100
100
|
const changeInputRef = useRef<HTMLInputElement>(null)
|
|
101
101
|
const btnRef = useRef<HTMLButtonElement>(null)
|
|
102
102
|
const wrapperRef = useRef<HTMLDivElement>(null)
|
|
@@ -383,7 +383,7 @@ export function useDatepickerState(props: IPktDatepicker, ref: React.ForwardedRe
|
|
|
383
383
|
e.nativeEvent,
|
|
384
384
|
() => toggleCalendar(),
|
|
385
385
|
() => submitFormOrBlur(inputRef.current),
|
|
386
|
-
() =>
|
|
386
|
+
() => inputToRef.current?.focus(),
|
|
387
387
|
() => inputRef.current?.blur(),
|
|
388
388
|
)
|
|
389
389
|
},
|
|
@@ -395,9 +395,9 @@ export function useDatepickerState(props: IPktDatepicker, ref: React.ForwardedRe
|
|
|
395
395
|
handleDatepickerKeydown(
|
|
396
396
|
e.nativeEvent,
|
|
397
397
|
() => toggleCalendar(),
|
|
398
|
-
() => submitFormOrBlur(
|
|
398
|
+
() => submitFormOrBlur(inputToRef.current),
|
|
399
399
|
undefined,
|
|
400
|
-
() =>
|
|
400
|
+
() => inputToRef.current?.blur(),
|
|
401
401
|
)
|
|
402
402
|
},
|
|
403
403
|
[toggleCalendar, submitFormOrBlur],
|
|
@@ -421,9 +421,11 @@ export function useDatepickerState(props: IPktDatepicker, ref: React.ForwardedRe
|
|
|
421
421
|
useEffect(() => {
|
|
422
422
|
const form = wrapperRef.current?.closest('form')
|
|
423
423
|
if (!form) return
|
|
424
|
+
let resetTimeout: number | undefined
|
|
424
425
|
|
|
425
426
|
const handleReset = () => {
|
|
426
|
-
window.
|
|
427
|
+
window.clearTimeout(resetTimeout)
|
|
428
|
+
resetTimeout = window.setTimeout(() => {
|
|
427
429
|
setInternalValue(initialValuesRef.current)
|
|
428
430
|
setCalendarOpen(false)
|
|
429
431
|
if (changeInputRef.current) {
|
|
@@ -433,7 +435,10 @@ export function useDatepickerState(props: IPktDatepicker, ref: React.ForwardedRe
|
|
|
433
435
|
}
|
|
434
436
|
|
|
435
437
|
form.addEventListener('reset', handleReset)
|
|
436
|
-
return () =>
|
|
438
|
+
return () => {
|
|
439
|
+
form.removeEventListener('reset', handleReset)
|
|
440
|
+
window.clearTimeout(resetTimeout)
|
|
441
|
+
}
|
|
437
442
|
}, [])
|
|
438
443
|
|
|
439
444
|
// Expose value getter/setter on ref for RHF register() compatibility.
|
|
@@ -515,7 +520,7 @@ export function useDatepickerState(props: IPktDatepicker, ref: React.ForwardedRe
|
|
|
515
520
|
isInputDisabled,
|
|
516
521
|
hasCounter,
|
|
517
522
|
inputRef,
|
|
518
|
-
|
|
523
|
+
inputToRef,
|
|
519
524
|
changeInputRef,
|
|
520
525
|
btnRef,
|
|
521
526
|
wrapperRef,
|
|
@@ -12,7 +12,6 @@ import {
|
|
|
12
12
|
useState,
|
|
13
13
|
} from 'react'
|
|
14
14
|
|
|
15
|
-
|
|
16
15
|
import { PktIcon } from '../icon/Icon'
|
|
17
16
|
import { FileItem, TFileItemList, TUploadStrategy } from './types'
|
|
18
17
|
import { usePktStrings } from '../../hooks/usePktStrings'
|
|
@@ -27,7 +26,8 @@ import type { IPktStringsProps } from 'shared-strings'
|
|
|
27
26
|
* - optionally rendering hidden inputs with file IDs when `uploadStrategy="custom"`
|
|
28
27
|
*/
|
|
29
28
|
interface IDropZoneProps
|
|
30
|
-
extends
|
|
29
|
+
extends
|
|
30
|
+
Omit<InputHTMLAttributes<HTMLInputElement>, 'checked' | 'size' | 'type' | 'value' | 'onChange' | 'width'>,
|
|
31
31
|
IPktStringsProps<'fileupload'> {
|
|
32
32
|
/** Called with `FileItem`s created from dropped/selected files. */
|
|
33
33
|
onFilesAdded?: (files: TFileItemList) => void
|
|
@@ -211,18 +211,18 @@ export const DropZone = forwardRef<HTMLInputElement, IDropZoneProps>(
|
|
|
211
211
|
accept={resolvedAccept}
|
|
212
212
|
disabled={disabled}
|
|
213
213
|
name={(uploadStrategy === 'form' && name) || undefined} // Ikke sett name hvis uploadStrategy er 'custom' - ignorerer ved POST
|
|
214
|
-
aria-label={
|
|
214
|
+
aria-label={
|
|
215
|
+
hasVisibleLabel
|
|
216
|
+
? undefined
|
|
217
|
+
: multiple
|
|
218
|
+
? s.fileupload.openFileDialogLabelMultiple
|
|
219
|
+
: s.fileupload.openFileDialogLabelSingle
|
|
220
|
+
}
|
|
215
221
|
/>
|
|
216
222
|
{uploadStrategy === 'custom' && (
|
|
217
223
|
<>
|
|
218
224
|
{value?.map((fileItem) => (
|
|
219
|
-
<input
|
|
220
|
-
key={fileItem.fileId}
|
|
221
|
-
type="hidden"
|
|
222
|
-
name={name}
|
|
223
|
-
form={inputProps.form}
|
|
224
|
-
value={fileItem.fileId}
|
|
225
|
-
/>
|
|
225
|
+
<input key={fileItem.fileId} type="hidden" name={name} form={inputProps.form} value={fileItem.fileId} />
|
|
226
226
|
))}
|
|
227
227
|
</>
|
|
228
228
|
)}
|
|
@@ -224,10 +224,7 @@ export const PktFileUpload: FC<IPktFileUpload> = forwardRef<HTMLInputElement, IP
|
|
|
224
224
|
uploadStrategy,
|
|
225
225
|
required,
|
|
226
226
|
currentFileCount: value.length,
|
|
227
|
-
onMissingFiles: useCallback(
|
|
228
|
-
() => setValidationError(fileuploadStrings.requiredMissing),
|
|
229
|
-
[fileuploadStrings],
|
|
230
|
-
),
|
|
227
|
+
onMissingFiles: useCallback(() => setValidationError(fileuploadStrings.requiredMissing), [fileuploadStrings]),
|
|
231
228
|
})
|
|
232
229
|
|
|
233
230
|
const itemRenderer = typeof itemRendererProp === 'string' ? ItemRenderers[itemRendererProp] : itemRendererProp
|
|
@@ -310,23 +307,19 @@ export const PktFileUpload: FC<IPktFileUpload> = forwardRef<HTMLInputElement, IP
|
|
|
310
307
|
|
|
311
308
|
const queueItemOperations = useMemo<TQueueItemOperation[]>(() => {
|
|
312
309
|
const operations: TQueueItemOperation[] = []
|
|
313
|
-
if (effectiveRenameEnabled) operations.push(renameFileOperation)
|
|
314
|
-
if (effectiveCommentsEnabled) operations.push(addCommentOperation)
|
|
310
|
+
if (effectiveRenameEnabled) operations.push(renameFileOperation(fileuploadStrings))
|
|
311
|
+
if (effectiveCommentsEnabled) operations.push(addCommentOperation(fileuploadStrings))
|
|
315
312
|
operations.push(...extraOperations)
|
|
316
|
-
operations.push(removeFileOperation(onFileRemoved))
|
|
313
|
+
operations.push(removeFileOperation(onFileRemoved, fileuploadStrings))
|
|
317
314
|
return operations
|
|
318
|
-
}, [effectiveRenameEnabled, effectiveCommentsEnabled, extraOperations, onFileRemoved])
|
|
315
|
+
}, [effectiveRenameEnabled, effectiveCommentsEnabled, extraOperations, onFileRemoved, fileuploadStrings])
|
|
319
316
|
|
|
320
317
|
const { totalCount, uploadedCount, failedCount } = useMemo(
|
|
321
318
|
() => countFileTransferStates(value, transfers),
|
|
322
319
|
[value, transfers],
|
|
323
320
|
)
|
|
324
321
|
|
|
325
|
-
const totalLabel = plural(
|
|
326
|
-
totalCount,
|
|
327
|
-
fileuploadStrings.fileLabelOne,
|
|
328
|
-
fileuploadStrings.fileLabelOther,
|
|
329
|
-
)
|
|
322
|
+
const totalLabel = plural(totalCount, fileuploadStrings.fileLabelOne, fileuploadStrings.fileLabelOther)
|
|
330
323
|
|
|
331
324
|
const fileUploadContent = (
|
|
332
325
|
<div
|
|
@@ -338,7 +331,9 @@ export const PktFileUpload: FC<IPktFileUpload> = forwardRef<HTMLInputElement, IP
|
|
|
338
331
|
aria-disabled={disabled}
|
|
339
332
|
{...(disabled ? { inert: true } : {})}
|
|
340
333
|
>
|
|
341
|
-
<PktFileUploadContext.Provider
|
|
334
|
+
<PktFileUploadContext.Provider
|
|
335
|
+
value={{ name: props.name || '', multiple: !!multiple, id, strings: fileuploadStrings }}
|
|
336
|
+
>
|
|
342
337
|
<div className="pkt-sr-only" aria-live="polite" aria-atomic="true">
|
|
343
338
|
{addedAnnouncement ||
|
|
344
339
|
(totalCount > 0 && uploadedCount > 0
|