@oslokommune/punkt-react 13.17.0 → 13.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 +38 -0
- package/README.md +0 -6
- package/dist/index.d.ts +1 -0
- package/dist/punkt-react.es.js +1012 -1002
- package/dist/punkt-react.umd.js +42 -42
- package/package.json +4 -4
- package/src/components/checkbox/Checkbox.test.tsx +36 -0
- package/src/components/checkbox/Checkbox.tsx +20 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oslokommune/punkt-react",
|
|
3
|
-
"version": "13.
|
|
3
|
+
"version": "13.18.1",
|
|
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",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@lit-labs/ssr-dom-shim": "^1.2.1",
|
|
41
41
|
"@lit/react": "^1.0.7",
|
|
42
|
-
"@oslokommune/punkt-elements": "^13.
|
|
42
|
+
"@oslokommune/punkt-elements": "^13.18.1",
|
|
43
43
|
"classnames": "^2.5.1",
|
|
44
44
|
"prettier": "^3.3.3",
|
|
45
45
|
"react-hook-form": "^7.53.0"
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"@babel/plugin-transform-private-property-in-object": "^7.25.9",
|
|
49
49
|
"@oslokommune/punkt-assets": "^13.16.0",
|
|
50
|
-
"@oslokommune/punkt-css": "^13.
|
|
50
|
+
"@oslokommune/punkt-css": "^13.18.1",
|
|
51
51
|
"@testing-library/jest-dom": "^6.5.0",
|
|
52
52
|
"@testing-library/react": "^16.0.1",
|
|
53
53
|
"@testing-library/user-event": "^14.5.2",
|
|
@@ -103,5 +103,5 @@
|
|
|
103
103
|
"url": "https://github.com/oslokommune/punkt/issues"
|
|
104
104
|
},
|
|
105
105
|
"license": "MIT",
|
|
106
|
-
"gitHead": "
|
|
106
|
+
"gitHead": "3a29f3b3de9cced943ed4cd7de3d6c8a02e75040"
|
|
107
107
|
}
|
|
@@ -58,6 +58,42 @@ describe('PktCheckbox', () => {
|
|
|
58
58
|
expect(onClickMock).toHaveBeenCalledTimes(1)
|
|
59
59
|
})
|
|
60
60
|
|
|
61
|
+
test('renders indeterminate checkbox', async () => {
|
|
62
|
+
const { getByRole } = render(<PktCheckbox id="myCheckbox" label="My Checkbox" indeterminate={true} />)
|
|
63
|
+
|
|
64
|
+
const checkbox = getByRole('checkbox') as HTMLInputElement
|
|
65
|
+
|
|
66
|
+
// Verify that the checkbox is in indeterminate state
|
|
67
|
+
expect(checkbox.indeterminate).toBe(true)
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
test('handles indeterminate state changes', async () => {
|
|
71
|
+
const { getByRole, rerender } = render(<PktCheckbox id="myCheckbox" label="My Checkbox" indeterminate={false} />)
|
|
72
|
+
|
|
73
|
+
const checkbox = getByRole('checkbox') as HTMLInputElement
|
|
74
|
+
expect(checkbox.indeterminate).toBe(false)
|
|
75
|
+
|
|
76
|
+
// Re-render with indeterminate true
|
|
77
|
+
rerender(<PktCheckbox id="myCheckbox" label="My Checkbox" indeterminate={true} />)
|
|
78
|
+
expect(checkbox.indeterminate).toBe(true)
|
|
79
|
+
|
|
80
|
+
// Re-render with indeterminate false again
|
|
81
|
+
rerender(<PktCheckbox id="myCheckbox" label="My Checkbox" indeterminate={false} />)
|
|
82
|
+
expect(checkbox.indeterminate).toBe(false)
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
test('indeterminate state is independent of checked state', async () => {
|
|
86
|
+
const { getByRole } = render(
|
|
87
|
+
<PktCheckbox id="myCheckbox" label="My Checkbox" indeterminate={true} checked={true} />,
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
const checkbox = getByRole('checkbox') as HTMLInputElement
|
|
91
|
+
|
|
92
|
+
// Both can be true simultaneously
|
|
93
|
+
expect(checkbox.indeterminate).toBe(true)
|
|
94
|
+
expect(checkbox.checked).toBe(true)
|
|
95
|
+
})
|
|
96
|
+
|
|
61
97
|
describe('accessibility', () => {
|
|
62
98
|
it('renders with no wcag errors with axe', async () => {
|
|
63
99
|
const { container } = render(<PktCheckbox id="accessibilityTest" label="My checkkbox"></PktCheckbox>)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ChangeEventHandler, ForwardedRef, forwardRef, ReactNode, ReactElement } from 'react'
|
|
1
|
+
import { ChangeEventHandler, ForwardedRef, forwardRef, ReactNode, ReactElement, useEffect, useRef } from 'react'
|
|
2
2
|
import type { InputHTMLAttributes } from 'react'
|
|
3
3
|
|
|
4
4
|
export interface IPktCheckbox extends InputHTMLAttributes<HTMLInputElement> {
|
|
@@ -10,6 +10,7 @@ export interface IPktCheckbox extends InputHTMLAttributes<HTMLInputElement> {
|
|
|
10
10
|
hasError?: boolean
|
|
11
11
|
defaultChecked?: boolean
|
|
12
12
|
checked?: boolean
|
|
13
|
+
indeterminate?: boolean
|
|
13
14
|
value?: string
|
|
14
15
|
isSwitch?: boolean
|
|
15
16
|
hideLabel?: boolean
|
|
@@ -37,6 +38,7 @@ export const PktCheckbox = forwardRef(
|
|
|
37
38
|
labelPosition = 'right',
|
|
38
39
|
defaultChecked,
|
|
39
40
|
checked,
|
|
41
|
+
indeterminate,
|
|
40
42
|
optionalTag,
|
|
41
43
|
optionalText = 'Valgfritt',
|
|
42
44
|
requiredTag,
|
|
@@ -46,6 +48,22 @@ export const PktCheckbox = forwardRef(
|
|
|
46
48
|
}: IPktCheckbox,
|
|
47
49
|
ref: ForwardedRef<HTMLInputElement>,
|
|
48
50
|
): ReactElement => {
|
|
51
|
+
const internalRef = useRef<HTMLInputElement>(null)
|
|
52
|
+
|
|
53
|
+
useEffect(() => {
|
|
54
|
+
if (internalRef.current && indeterminate !== undefined) {
|
|
55
|
+
internalRef.current.indeterminate = indeterminate
|
|
56
|
+
}
|
|
57
|
+
}, [indeterminate])
|
|
58
|
+
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
if (typeof ref === 'function') {
|
|
61
|
+
ref(internalRef.current)
|
|
62
|
+
} else if (ref) {
|
|
63
|
+
ref.current = internalRef.current
|
|
64
|
+
}
|
|
65
|
+
}, [ref])
|
|
66
|
+
|
|
49
67
|
const classes = [className, 'pkt-input-check'].filter(Boolean).join(' ')
|
|
50
68
|
|
|
51
69
|
const labelClasses = [
|
|
@@ -88,7 +106,7 @@ export const PktCheckbox = forwardRef(
|
|
|
88
106
|
)}
|
|
89
107
|
<input
|
|
90
108
|
role={isSwitch ? 'switch' : 'checkbox'}
|
|
91
|
-
ref={
|
|
109
|
+
ref={internalRef}
|
|
92
110
|
className={`pkt-input-check__input-checkbox ${hasError ? 'pkt-input-check__input-checkbox--error' : ''}`}
|
|
93
111
|
type="checkbox"
|
|
94
112
|
id={id}
|