@oslokommune/punkt-react 19.5.2 → 19.7.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 +25 -0
- package/dist/components/combobox/types.d.ts +3 -36
- package/dist/components/inputwrapper/InputWrapper.d.ts +2 -0
- package/dist/components/radio/RadioButton.d.ts +2 -0
- package/dist/components/timepicker/useTimepickerState.d.ts +1 -2
- package/dist/punkt-react.cjs +1 -1
- package/dist/punkt-react.js +1861 -1835
- package/dist/shared-types/checkbox.d.ts +3 -1
- package/dist/shared-types/combobox.d.ts +73 -5
- package/dist/shared-types/index.d.ts +3 -1
- package/dist/shared-types/size.d.ts +3 -2
- package/package.json +3 -3
- package/src/components/checkbox/Checkbox.test.tsx +24 -0
- package/src/components/checkbox/Checkbox.tsx +4 -1
- package/src/components/combobox/Combobox.tsx +1 -1
- package/src/components/combobox/ComboboxTags.tsx +1 -2
- package/src/components/combobox/types.ts +12 -44
- package/src/components/combobox/useComboboxState.ts +16 -19
- package/src/components/inputwrapper/InputWrapper.test.tsx +35 -0
- package/src/components/inputwrapper/InputWrapper.tsx +16 -1
- package/src/components/radio/RadioButton.test.tsx +26 -0
- package/src/components/radio/RadioButton.tsx +6 -1
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import type { IPktStringsProps } from '../shared-strings';
|
|
8
8
|
import type { IFormFieldErrorProps, IFormFieldLabelProps, ITagOptionalRequiredProps } from './form-field';
|
|
9
|
+
import type { TPktInputSize } from './size';
|
|
9
10
|
/** Checkbox label placement — shared runtime source for types, specs, and Preview. */
|
|
10
11
|
export declare const CHECKBOX_LABEL_POSITIONS: readonly ['right', 'left'];
|
|
11
12
|
export type TCheckboxLabelPosition = (typeof CHECKBOX_LABEL_POSITIONS)[number];
|
|
@@ -28,12 +29,13 @@ export interface IPktCheckboxBase extends IFormFieldLabelProps, Pick<IFormFieldE
|
|
|
28
29
|
isSwitch?: boolean;
|
|
29
30
|
hideLabel?: boolean;
|
|
30
31
|
labelPosition?: TCheckboxLabelPosition;
|
|
32
|
+
inputSize?: TPktInputSize;
|
|
31
33
|
}
|
|
32
34
|
/**
|
|
33
35
|
* Documented Checkbox props (subset of `IPktCheckboxBase`).
|
|
34
36
|
* Used for typed component specs in documentation.
|
|
35
37
|
*/
|
|
36
|
-
export type ICheckboxSpecProps = Pick<IPktCheckboxBase, 'label' | 'checkHelptext' | 'name' | 'form' | 'value' | 'id' | 'defaultChecked' | 'checked' | 'indeterminate' | 'hasTile' | 'disabled' | 'hasError' | 'isSwitch' | 'labelPosition' | 'hideLabel' | 'requiredTag' | 'requiredText' | 'optionalTag' | 'optionalText' | 'tagText'>;
|
|
38
|
+
export type ICheckboxSpecProps = Pick<IPktCheckboxBase, 'label' | 'checkHelptext' | 'name' | 'form' | 'value' | 'id' | 'defaultChecked' | 'checked' | 'indeterminate' | 'hasTile' | 'inputSize' | 'disabled' | 'hasError' | 'isSwitch' | 'labelPosition' | 'hideLabel' | 'requiredTag' | 'requiredText' | 'optionalTag' | 'optionalText' | 'tagText'>;
|
|
37
39
|
/**
|
|
38
40
|
* Default values for pkt-checkbox. Single source of truth for both frameworks.
|
|
39
41
|
* `checked` is intentionally absent — React must keep it `undefined` to stay uncontrolled.
|
|
@@ -2,14 +2,17 @@
|
|
|
2
2
|
* combobox.ts
|
|
3
3
|
*
|
|
4
4
|
* Type definitions for the combobox and listbox components.
|
|
5
|
-
* Used by both Elements and React implementations
|
|
6
|
-
*
|
|
5
|
+
* Used by both Elements and React implementations,
|
|
6
|
+
* the shared combobox helper functions, and typed component specs.
|
|
7
7
|
*/
|
|
8
|
+
import type { IFormFieldErrorProps, IFormFieldLabelProps, IHelptextProps, ITagOptionalRequiredProps } from './form-field';
|
|
9
|
+
import type { TPktInputSize } from './size';
|
|
8
10
|
/**
|
|
9
11
|
* Tag skin colors available for combobox option tags.
|
|
10
12
|
* Matches the TTagSkin values from the tag component.
|
|
11
13
|
*/
|
|
12
|
-
export
|
|
14
|
+
export declare const COMBOBOX_TAG_SKINS: readonly ['blue', 'blue-dark', 'blue-light', 'green', 'red', 'yellow', 'beige', 'gray', 'grey'];
|
|
15
|
+
export type TPktComboboxTagSkin = (typeof COMBOBOX_TAG_SKINS)[number];
|
|
13
16
|
/**
|
|
14
17
|
* Represents a single option in a combobox or listbox.
|
|
15
18
|
*/
|
|
@@ -27,8 +30,73 @@ export interface IPktComboboxOption {
|
|
|
27
30
|
/**
|
|
28
31
|
* How the selected value is displayed in the combobox input.
|
|
29
32
|
*/
|
|
30
|
-
export
|
|
33
|
+
export declare const COMBOBOX_DISPLAY_VALUES: readonly ['label', 'value', 'prefixAndValue'];
|
|
34
|
+
export type TPktComboboxDisplayValue = (typeof COMBOBOX_DISPLAY_VALUES)[number];
|
|
31
35
|
/**
|
|
32
36
|
* Placement of selected value tags in multiple selection mode.
|
|
33
37
|
*/
|
|
34
|
-
export
|
|
38
|
+
export declare const COMBOBOX_TAG_PLACEMENTS: readonly ['inside', 'outside'];
|
|
39
|
+
export type TPktComboboxTagPlacement = (typeof COMBOBOX_TAG_PLACEMENTS)[number];
|
|
40
|
+
/**
|
|
41
|
+
* Combobox props shared by React, Elements, and typed component specs.
|
|
42
|
+
*
|
|
43
|
+
* @remarks Both frameworks extend this with `Omit<>` and widen a few props:
|
|
44
|
+
* - React widens `helptext`, `helptextDropdown` and `errorMessage` to `ReactNode`.
|
|
45
|
+
* - Elements widens string/number props to `| null` (Lit uses `null` for an unset attribute,
|
|
46
|
+
* see `PktInputElement`) and `useWrapper` to `Booleanish`. Elements omits `form`, which is
|
|
47
|
+
* a getter returning the associated `HTMLFormElement`, not the form id.
|
|
48
|
+
*
|
|
49
|
+
* `hasFieldset` and `counter` are tri-state: `null` means the component derives the value.
|
|
50
|
+
*/
|
|
51
|
+
export interface IPktComboboxBase extends IFormFieldLabelProps, IHelptextProps, IFormFieldErrorProps, ITagOptionalRequiredProps {
|
|
52
|
+
id?: string;
|
|
53
|
+
name?: string;
|
|
54
|
+
form?: string;
|
|
55
|
+
ariaDescribedby?: string;
|
|
56
|
+
placeholder?: string;
|
|
57
|
+
required?: boolean;
|
|
58
|
+
value?: string | string[];
|
|
59
|
+
defaultValue?: string | string[];
|
|
60
|
+
options?: IPktComboboxOption[];
|
|
61
|
+
defaultOptions?: IPktComboboxOption[];
|
|
62
|
+
multiple?: boolean;
|
|
63
|
+
maxlength?: number;
|
|
64
|
+
typeahead?: boolean;
|
|
65
|
+
includeSearch?: boolean;
|
|
66
|
+
allowUserInput?: boolean;
|
|
67
|
+
searchPlaceholder?: string;
|
|
68
|
+
displayValueAs?: TPktComboboxDisplayValue;
|
|
69
|
+
tagPlacement?: TPktComboboxTagPlacement;
|
|
70
|
+
inputSize?: TPktInputSize;
|
|
71
|
+
fullwidth?: boolean;
|
|
72
|
+
inline?: boolean;
|
|
73
|
+
useWrapper?: boolean;
|
|
74
|
+
hasFieldset?: boolean | null;
|
|
75
|
+
counter?: boolean | null;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Documented Combobox props (subset of `IPktComboboxBase`).
|
|
79
|
+
* Used for typed component specs in documentation.
|
|
80
|
+
*/
|
|
81
|
+
export type IComboboxSpecProps = Pick<IPktComboboxBase, 'name' | 'form' | 'ariaDescribedby' | 'id' | 'label' | 'placeholder' | 'multiple' | 'tagPlacement' | 'maxlength' | 'typeahead' | 'includeSearch' | 'allowUserInput' | 'searchPlaceholder' | 'displayValueAs' | 'inputSize' | 'value' | 'helptext' | 'helptextDropdown' | 'helptextDropdownButton' | 'disabled' | 'hasError' | 'errorMessage' | 'required' | 'requiredTag' | 'requiredText' | 'optionalTag' | 'optionalText' | 'tagText' | 'fullwidth' | 'defaultOptions' | 'options' | 'inline' | 'useWrapper' | 'hasFieldset' | 'counter' | 'defaultValue'>;
|
|
82
|
+
/**
|
|
83
|
+
* Default values for pkt-combobox. Single source of truth for both frameworks.
|
|
84
|
+
* Array defaults (`options`, `defaultOptions`) are intentionally absent — a shared array
|
|
85
|
+
* instance would be mutated across component instances.
|
|
86
|
+
*/
|
|
87
|
+
export declare const COMBOBOX_DEFAULTS: {
|
|
88
|
+
readonly multiple: false;
|
|
89
|
+
readonly typeahead: false;
|
|
90
|
+
readonly includeSearch: false;
|
|
91
|
+
readonly allowUserInput: false;
|
|
92
|
+
readonly displayValueAs: 'label';
|
|
93
|
+
readonly inputSize: 'medium';
|
|
94
|
+
readonly disabled: false;
|
|
95
|
+
readonly hasError: false;
|
|
96
|
+
readonly required: false;
|
|
97
|
+
readonly requiredTag: false;
|
|
98
|
+
readonly optionalTag: false;
|
|
99
|
+
readonly fullwidth: false;
|
|
100
|
+
readonly inline: false;
|
|
101
|
+
readonly useWrapper: true;
|
|
102
|
+
};
|
|
@@ -20,6 +20,7 @@ export type { TIconSizeClass, IPktIconBase, IIconSpecProps } from './icon';
|
|
|
20
20
|
export { LAYOUT_DIRECTIONS } from './layout';
|
|
21
21
|
export type { TLayout, TVerticalPosition, THorizontalPosition, TPosition, TPositionWithCenter, } from './layout';
|
|
22
22
|
export type { THTMLButtonType, TSelectionMode } from './form';
|
|
23
|
+
export { INPUT_SIZES } from './size';
|
|
23
24
|
export type { TPktInputSize, TSize3, TSize5, TSize7 } from './size';
|
|
24
25
|
export { ACCORDION_SKINS } from './accordion';
|
|
25
26
|
export type { TAccordionSkin, IPktAccordionBase, IPktAccordionItemBase, IAccordionSpecProps, IAccordionItemSpecProps, IAccordionVisualProps, } from './accordion';
|
|
@@ -41,7 +42,8 @@ export { defaultSingleStrings, defaultRangeStrings } from './datepicker';
|
|
|
41
42
|
export type { ITimepickerStrings } from './timepicker';
|
|
42
43
|
export { defaultTimepickerStrings } from './timepicker';
|
|
43
44
|
export type { TProgressbarRole, TProgressbarSkin, TProgressbarStatusPlacement, TProgressbarStatusType, TProgressbarTitlePosition, } from './progressbar';
|
|
44
|
-
export
|
|
45
|
+
export { COMBOBOX_TAG_SKINS, COMBOBOX_DISPLAY_VALUES, COMBOBOX_TAG_PLACEMENTS, COMBOBOX_DEFAULTS, } from './combobox';
|
|
46
|
+
export type { IPktComboboxOption, TPktComboboxTagSkin, TPktComboboxDisplayValue, TPktComboboxTagPlacement, IPktComboboxBase, IComboboxSpecProps, } from './combobox';
|
|
45
47
|
export type { IPktSelectOption, TSelectOption } from './select';
|
|
46
48
|
export type { TPktSearchInputAppearance, TPktSearchInputMethod, IPktSearchInputSuggestion, IPktSearchInput, } from './searchinput';
|
|
47
49
|
export { UPLOAD_STRATEGIES, FILE_UPLOAD_ITEM_RENDERERS, PREVIEW_UPLOAD_STATUS, } from './fileupload';
|
|
@@ -17,6 +17,7 @@ export type TSize5 = 'xsmall' | 'small' | 'medium' | 'large' | 'xlarge';
|
|
|
17
17
|
*/
|
|
18
18
|
export type TSize7 = 'xxsmall' | 'xsmall' | 'small' | 'medium' | 'large' | 'xlarge' | 'xxlarge';
|
|
19
19
|
/**
|
|
20
|
-
* Sizes used in our input components
|
|
20
|
+
* Sizes used in our input components — shared runtime source for types, specs, and Preview.
|
|
21
21
|
*/
|
|
22
|
-
export
|
|
22
|
+
export declare const INPUT_SIZES: readonly ['xsmall', 'small', 'medium'];
|
|
23
|
+
export type TPktInputSize = (typeof INPUT_SIZES)[number];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oslokommune/punkt-react",
|
|
3
|
-
"version": "19.
|
|
3
|
+
"version": "19.7.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",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"@eslint/eslintrc": "^3.3.5",
|
|
42
42
|
"@eslint/js": "^10.0.1",
|
|
43
43
|
"@oslokommune/punkt-assets": "^19.0.4",
|
|
44
|
-
"@oslokommune/punkt-css": "^19.
|
|
44
|
+
"@oslokommune/punkt-css": "^19.6.0",
|
|
45
45
|
"@testing-library/jest-dom": "^6.9.1",
|
|
46
46
|
"@testing-library/react": "^16.3.2",
|
|
47
47
|
"@testing-library/user-event": "^14.6.1",
|
|
@@ -101,5 +101,5 @@
|
|
|
101
101
|
"url": "https://github.com/oslokommune/punkt/issues"
|
|
102
102
|
},
|
|
103
103
|
"license": "MIT",
|
|
104
|
-
"gitHead": "
|
|
104
|
+
"gitHead": "f5f319f536d0fcbd3943ed6e191d887112e3c192"
|
|
105
105
|
}
|
|
@@ -105,3 +105,27 @@ describe('PktCheckbox', () => {
|
|
|
105
105
|
})
|
|
106
106
|
})
|
|
107
107
|
})
|
|
108
|
+
|
|
109
|
+
describe('PktCheckbox inputSize', () => {
|
|
110
|
+
const root = (inputSize?: 'small' | 'medium' | 'xsmall') =>
|
|
111
|
+
render(<PktCheckbox id="s" label="Valg" inputSize={inputSize} />).container.querySelector('.pkt-input-check')
|
|
112
|
+
|
|
113
|
+
it('adds no size class without inputSize, so the size is inherited', () => {
|
|
114
|
+
expect(root()?.className).toBe('pkt-input-check')
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
it('adds the size class for inputSize', () => {
|
|
118
|
+
expect(root('small')).toHaveClass('pkt-input-check--small')
|
|
119
|
+
expect(root('xsmall')).toHaveClass('pkt-input-check--xsmall')
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
it('adds the medium class when medium is set explicitly', () => {
|
|
123
|
+
expect(root('medium')).toHaveClass('pkt-input-check--medium')
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
it('does not pass inputSize on to the native input', () => {
|
|
127
|
+
render(<PktCheckbox id="n" label="Valg" inputSize="small" />)
|
|
128
|
+
expect(document.getElementById('n')).not.toHaveAttribute('inputsize')
|
|
129
|
+
expect(document.getElementById('n')).not.toHaveAttribute('inputSize')
|
|
130
|
+
})
|
|
131
|
+
})
|
|
@@ -34,6 +34,7 @@ export const PktCheckbox = forwardRef(
|
|
|
34
34
|
isSwitch = CHECKBOX_DEFAULTS.isSwitch,
|
|
35
35
|
hideLabel = CHECKBOX_DEFAULTS.hideLabel,
|
|
36
36
|
labelPosition = CHECKBOX_DEFAULTS.labelPosition,
|
|
37
|
+
inputSize,
|
|
37
38
|
defaultChecked,
|
|
38
39
|
checked,
|
|
39
40
|
indeterminate,
|
|
@@ -66,7 +67,9 @@ export const PktCheckbox = forwardRef(
|
|
|
66
67
|
}
|
|
67
68
|
}, [ref])
|
|
68
69
|
|
|
69
|
-
const classes = [className, 'pkt-input-check'
|
|
70
|
+
const classes = [className, 'pkt-input-check', inputSize ? `pkt-input-check--${inputSize}` : '']
|
|
71
|
+
.filter(Boolean)
|
|
72
|
+
.join(' ')
|
|
70
73
|
|
|
71
74
|
const labelClasses = [
|
|
72
75
|
'pkt-input-check__input-label',
|
|
@@ -44,7 +44,7 @@ export const PktCombobox = forwardRef<HTMLDivElement, IPktCombobox>((props, ref)
|
|
|
44
44
|
tagText={state.tagText}
|
|
45
45
|
useWrapper={state.useWrapper}
|
|
46
46
|
inline={state.inline}
|
|
47
|
-
size={
|
|
47
|
+
size={state.inputSize}
|
|
48
48
|
counter={state.hasCounter}
|
|
49
49
|
counterCurrent={state.values.length}
|
|
50
50
|
counterMaxLength={state.maxlength}
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
import { useEffect, useRef, type MouseEvent, type KeyboardEvent } from 'react'
|
|
4
4
|
import { findOptionByValue, getOptionDisplayText } from 'shared-utils/combobox'
|
|
5
|
-
import type { TPktComboboxDisplayValue } from 'shared-types/combobox'
|
|
6
5
|
import { PktTag } from '../tag/Tag'
|
|
7
6
|
import type { IComboboxState } from './types'
|
|
8
7
|
|
|
@@ -104,7 +103,7 @@ export const SingleValueDisplay = ({ state }: ISingleValueDisplayProps) => {
|
|
|
104
103
|
const option = findOptionByValue(options, values[0])
|
|
105
104
|
if (!option) return null
|
|
106
105
|
|
|
107
|
-
const displayText = getOptionDisplayText(option, displayValueAs
|
|
106
|
+
const displayText = getOptionDisplayText(option, displayValueAs)
|
|
108
107
|
|
|
109
108
|
return <span className="pkt-combobox__value">{displayText}</span>
|
|
110
109
|
}
|
|
@@ -12,52 +12,20 @@ import type {
|
|
|
12
12
|
ReactNode,
|
|
13
13
|
RefObject,
|
|
14
14
|
} from 'react'
|
|
15
|
-
import type {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
maxlength?: number
|
|
27
|
-
typeahead?: boolean
|
|
28
|
-
includeSearch?: boolean
|
|
29
|
-
allowUserInput?: boolean
|
|
30
|
-
displayValueAs?: TPktComboboxDisplayValue
|
|
31
|
-
tagPlacement?: TPktComboboxTagPlacement
|
|
32
|
-
searchPlaceholder?: string
|
|
33
|
-
|
|
34
|
-
// Form
|
|
35
|
-
name?: string
|
|
36
|
-
form?: string
|
|
37
|
-
ariaDescribedby?: string
|
|
38
|
-
id?: string
|
|
39
|
-
disabled?: boolean
|
|
40
|
-
required?: boolean
|
|
41
|
-
placeholder?: string
|
|
42
|
-
|
|
43
|
-
// InputWrapper props
|
|
44
|
-
label?: string
|
|
15
|
+
import type {
|
|
16
|
+
IPktComboboxBase,
|
|
17
|
+
IPktComboboxOption,
|
|
18
|
+
TPktComboboxDisplayValue,
|
|
19
|
+
TPktComboboxTagPlacement,
|
|
20
|
+
} from 'shared-types/combobox'
|
|
21
|
+
|
|
22
|
+
export interface IPktCombobox
|
|
23
|
+
extends
|
|
24
|
+
Omit<IPktComboboxBase, 'helptext' | 'helptextDropdown' | 'errorMessage'>,
|
|
25
|
+
IPktStringsProps<'combobox' | 'listbox' | 'forms' | 'validation'> {
|
|
45
26
|
helptext?: string | ReactNode
|
|
46
27
|
helptextDropdown?: string | ReactNode
|
|
47
|
-
helptextDropdownButton?: string
|
|
48
|
-
hasError?: boolean
|
|
49
28
|
errorMessage?: string | ReactNode
|
|
50
|
-
fullwidth?: boolean
|
|
51
|
-
requiredTag?: boolean
|
|
52
|
-
requiredText?: string
|
|
53
|
-
optionalTag?: boolean
|
|
54
|
-
optionalText?: string
|
|
55
|
-
tagText?: string
|
|
56
|
-
useWrapper?: boolean
|
|
57
|
-
inline?: boolean
|
|
58
|
-
counter?: boolean
|
|
59
|
-
hasFieldset?: boolean
|
|
60
|
-
inputSize?: 'small' | 'medium' | 'xsmall'
|
|
61
29
|
|
|
62
30
|
// Events
|
|
63
31
|
onChange?: ChangeEventHandler<HTMLInputElement>
|
|
@@ -119,7 +87,7 @@ export interface IComboboxState {
|
|
|
119
87
|
optionalText?: string
|
|
120
88
|
requiredTag: boolean
|
|
121
89
|
requiredText?: string
|
|
122
|
-
tagText?: string
|
|
90
|
+
tagText?: string | null
|
|
123
91
|
useWrapper: boolean
|
|
124
92
|
inline: boolean
|
|
125
93
|
inputSize: 'small' | 'medium' | 'xsmall'
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
useRef,
|
|
12
12
|
useState,
|
|
13
13
|
} from 'react'
|
|
14
|
-
import
|
|
14
|
+
import { COMBOBOX_DEFAULTS, type IPktComboboxOption } from 'shared-types/combobox'
|
|
15
15
|
import {
|
|
16
16
|
findOptionByValue,
|
|
17
17
|
getOptionDisplayText,
|
|
@@ -54,32 +54,32 @@ export function useComboboxState(props: IPktCombobox, ref: React.ForwardedRef<HT
|
|
|
54
54
|
defaultValue,
|
|
55
55
|
options: optionsProp,
|
|
56
56
|
defaultOptions,
|
|
57
|
-
multiple =
|
|
57
|
+
multiple = COMBOBOX_DEFAULTS.multiple,
|
|
58
58
|
maxlength,
|
|
59
|
-
typeahead =
|
|
60
|
-
includeSearch =
|
|
61
|
-
allowUserInput =
|
|
62
|
-
displayValueAs =
|
|
59
|
+
typeahead = COMBOBOX_DEFAULTS.typeahead,
|
|
60
|
+
includeSearch = COMBOBOX_DEFAULTS.includeSearch,
|
|
61
|
+
allowUserInput = COMBOBOX_DEFAULTS.allowUserInput,
|
|
62
|
+
displayValueAs = COMBOBOX_DEFAULTS.displayValueAs,
|
|
63
63
|
tagPlacement,
|
|
64
64
|
searchPlaceholder,
|
|
65
65
|
placeholder,
|
|
66
|
-
disabled =
|
|
67
|
-
required =
|
|
68
|
-
fullwidth =
|
|
69
|
-
hasError =
|
|
66
|
+
disabled = COMBOBOX_DEFAULTS.disabled,
|
|
67
|
+
required = COMBOBOX_DEFAULTS.required,
|
|
68
|
+
fullwidth = COMBOBOX_DEFAULTS.fullwidth,
|
|
69
|
+
hasError = COMBOBOX_DEFAULTS.hasError,
|
|
70
70
|
errorMessage,
|
|
71
71
|
helptext,
|
|
72
72
|
helptextDropdown,
|
|
73
73
|
helptextDropdownButton,
|
|
74
|
-
optionalTag =
|
|
74
|
+
optionalTag = COMBOBOX_DEFAULTS.optionalTag,
|
|
75
75
|
optionalText,
|
|
76
|
-
requiredTag =
|
|
76
|
+
requiredTag = COMBOBOX_DEFAULTS.requiredTag,
|
|
77
77
|
requiredText,
|
|
78
78
|
tagText,
|
|
79
|
-
useWrapper =
|
|
80
|
-
inline =
|
|
79
|
+
useWrapper = COMBOBOX_DEFAULTS.useWrapper,
|
|
80
|
+
inline = COMBOBOX_DEFAULTS.inline,
|
|
81
81
|
counter,
|
|
82
|
-
inputSize =
|
|
82
|
+
inputSize = COMBOBOX_DEFAULTS.inputSize,
|
|
83
83
|
name,
|
|
84
84
|
form,
|
|
85
85
|
ariaDescribedby,
|
|
@@ -427,10 +427,7 @@ export function useComboboxState(props: IPktCombobox, ref: React.ForwardedRef<HT
|
|
|
427
427
|
// The two modes resolve displayValueAs through different helpers.
|
|
428
428
|
newMessageValue = hasTextInput
|
|
429
429
|
? getSingleValueForInput(valueFromOptions || '', options, displayValueAs)
|
|
430
|
-
: getOptionDisplayText(
|
|
431
|
-
findOptionByValue(options, valueFromOptions),
|
|
432
|
-
displayValueAs as TPktComboboxDisplayValue,
|
|
433
|
-
)
|
|
430
|
+
: getOptionDisplayText(findOptionByValue(options, valueFromOptions), displayValueAs)
|
|
434
431
|
}
|
|
435
432
|
// Multi with room
|
|
436
433
|
else if (isMultiple && !isMaxItemsReached) {
|
|
@@ -55,3 +55,38 @@ describe('PktInputWrapper', () => {
|
|
|
55
55
|
})
|
|
56
56
|
})
|
|
57
57
|
})
|
|
58
|
+
|
|
59
|
+
describe('PktInputWrapper options container', () => {
|
|
60
|
+
const renderWrapper = (props: Partial<Parameters<typeof PktInputWrapper>[0]> = {}) =>
|
|
61
|
+
render(
|
|
62
|
+
<PktInputWrapper forId="g" label="Gruppe" {...props}>
|
|
63
|
+
<span className="valg">Valg</span>
|
|
64
|
+
</PktInputWrapper>,
|
|
65
|
+
).container
|
|
66
|
+
|
|
67
|
+
test('wraps the options of a fieldset in a vertical options container', () => {
|
|
68
|
+
const options = renderWrapper({ hasFieldset: true }).querySelector('.pkt-inputwrapper__options')
|
|
69
|
+
|
|
70
|
+
expect(options).not.toHaveClass('pkt-inputwrapper__options--horizontal')
|
|
71
|
+
expect(options?.querySelector('.valg')).toBeInTheDocument()
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
test('lays the options out horizontally with layout="horizontal"', () => {
|
|
75
|
+
const container = renderWrapper({ hasFieldset: true, layout: 'horizontal' })
|
|
76
|
+
|
|
77
|
+
expect(container.querySelector('.pkt-inputwrapper__options')).toHaveClass('pkt-inputwrapper__options--horizontal')
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
test('uses the options container for horizontal layout without a fieldset', () => {
|
|
81
|
+
const container = renderWrapper({ layout: 'horizontal' })
|
|
82
|
+
|
|
83
|
+
expect(container.querySelector('.pkt-inputwrapper__options--horizontal .valg')).toBeInTheDocument()
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
test('keeps the markup unchanged without a fieldset and horizontal layout', () => {
|
|
87
|
+
const container = renderWrapper()
|
|
88
|
+
|
|
89
|
+
expect(container.querySelector('.pkt-inputwrapper__options')).toBeNull()
|
|
90
|
+
expect(container.querySelector('.pkt-inputwrapper__fieldset > .valg')).toBeInTheDocument()
|
|
91
|
+
})
|
|
92
|
+
})
|
|
@@ -7,6 +7,7 @@ import { usePktStrings } from '../../hooks/usePktStrings'
|
|
|
7
7
|
import { formatString, type IPktStringsProps } from 'shared-strings'
|
|
8
8
|
import { counterStatusId, isCounterExceeded } from 'shared-utils/forms/described-by'
|
|
9
9
|
import { uuidish } from 'shared-utils/utils'
|
|
10
|
+
import type { TLayout } from 'shared-types'
|
|
10
11
|
import { PktAlert } from '../alert/Alert'
|
|
11
12
|
import { PktHelptext } from '../helptext/Helptext'
|
|
12
13
|
|
|
@@ -36,6 +37,7 @@ export interface IPktInputWrapper extends RefAttributes<HTMLElement>, IPktString
|
|
|
36
37
|
children?: ReactNode
|
|
37
38
|
className?: string
|
|
38
39
|
hasFieldset?: boolean
|
|
40
|
+
layout?: TLayout
|
|
39
41
|
role?: string
|
|
40
42
|
counterPosition?: 'top' | 'bottom'
|
|
41
43
|
size?: 'small' | 'medium' | 'xsmall'
|
|
@@ -66,6 +68,7 @@ export const PktInputWrapper = forwardRef(
|
|
|
66
68
|
children,
|
|
67
69
|
className = '',
|
|
68
70
|
hasFieldset = false,
|
|
71
|
+
layout = 'vertical',
|
|
69
72
|
role,
|
|
70
73
|
counterPosition = 'bottom',
|
|
71
74
|
size = 'medium',
|
|
@@ -193,7 +196,19 @@ export const PktInputWrapper = forwardRef(
|
|
|
193
196
|
{renderLabel()}
|
|
194
197
|
{renderHelptext()}
|
|
195
198
|
{counterTop && counterContent}
|
|
196
|
-
{
|
|
199
|
+
{hasFieldset || layout === 'horizontal' ? (
|
|
200
|
+
<div
|
|
201
|
+
className={
|
|
202
|
+
layout === 'horizontal'
|
|
203
|
+
? 'pkt-inputwrapper__options pkt-inputwrapper__options--horizontal'
|
|
204
|
+
: 'pkt-inputwrapper__options'
|
|
205
|
+
}
|
|
206
|
+
>
|
|
207
|
+
{children}
|
|
208
|
+
</div>
|
|
209
|
+
) : (
|
|
210
|
+
children
|
|
211
|
+
)}
|
|
197
212
|
{counterBottom && counterContent}
|
|
198
213
|
{hasError && errorMessage && (
|
|
199
214
|
<div className="pkt-inputwrapper__alert-wrapper">
|
|
@@ -66,3 +66,29 @@ describe('PktRadiobutton', () => {
|
|
|
66
66
|
})
|
|
67
67
|
})
|
|
68
68
|
})
|
|
69
|
+
|
|
70
|
+
describe('PktRadioButton inputSize', () => {
|
|
71
|
+
const root = (inputSize?: 'small' | 'medium' | 'xsmall') =>
|
|
72
|
+
render(<PktRadioButton id="s" name="g" label="Valg" inputSize={inputSize} />).container.querySelector(
|
|
73
|
+
'.pkt-input-check',
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
it('adds no size class without inputSize, so the size is inherited', () => {
|
|
77
|
+
expect(root()?.className).toBe('pkt-input-check')
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
it('adds the size class for inputSize', () => {
|
|
81
|
+
expect(root('small')).toHaveClass('pkt-input-check--small')
|
|
82
|
+
expect(root('xsmall')).toHaveClass('pkt-input-check--xsmall')
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
it('adds the medium class when medium is set explicitly', () => {
|
|
86
|
+
expect(root('medium')).toHaveClass('pkt-input-check--medium')
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
it('does not pass inputSize on to the native input', () => {
|
|
90
|
+
render(<PktRadioButton id="n" name="g" label="Valg" inputSize="small" />)
|
|
91
|
+
expect(document.getElementById('n')).not.toHaveAttribute('inputsize')
|
|
92
|
+
expect(document.getElementById('n')).not.toHaveAttribute('inputSize')
|
|
93
|
+
})
|
|
94
|
+
})
|
|
@@ -2,12 +2,14 @@ import { ChangeEventHandler, ForwardedRef, forwardRef, type InputHTMLAttributes,
|
|
|
2
2
|
import { usePktStrings } from '../../hooks/usePktStrings'
|
|
3
3
|
import { useGeneratedId } from '../../hooks/useGeneratedId'
|
|
4
4
|
import type { IPktStringsProps } from 'shared-strings'
|
|
5
|
+
import type { TPktInputSize } from 'shared-types'
|
|
5
6
|
|
|
6
7
|
export interface IPktRadioButton extends InputHTMLAttributes<HTMLInputElement>, IPktStringsProps<'forms'> {
|
|
7
8
|
id: string
|
|
8
9
|
name: string
|
|
9
10
|
label: string
|
|
10
11
|
hasTile?: boolean
|
|
12
|
+
inputSize?: TPktInputSize
|
|
11
13
|
disabled?: boolean
|
|
12
14
|
checkHelptext?: ReactNode | ReactNode[] | string
|
|
13
15
|
defaultChecked?: boolean
|
|
@@ -32,6 +34,7 @@ export const PktRadioButton = forwardRef(
|
|
|
32
34
|
label,
|
|
33
35
|
className,
|
|
34
36
|
hasTile = false,
|
|
37
|
+
inputSize,
|
|
35
38
|
disabled = false,
|
|
36
39
|
checkHelptext,
|
|
37
40
|
hasError = false,
|
|
@@ -50,7 +53,9 @@ export const PktRadioButton = forwardRef(
|
|
|
50
53
|
): ReactElement => {
|
|
51
54
|
const s = usePktStrings(['forms'], strings)
|
|
52
55
|
const id = useGeneratedId(idProp)
|
|
53
|
-
const classes = [className, 'pkt-input-check'
|
|
56
|
+
const classes = [className, 'pkt-input-check', inputSize ? `pkt-input-check--${inputSize}` : '']
|
|
57
|
+
.filter(Boolean)
|
|
58
|
+
.join(' ')
|
|
54
59
|
|
|
55
60
|
const inputTileClasses = [
|
|
56
61
|
'pkt-input-check__input',
|