@charcoal-ui/react 5.9.0-beta.1 → 5.10.0-beta.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/dist/components/DropdownSelector/index.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
- package/src/components/DropdownSelector/index.test.tsx +30 -0
- package/src/components/DropdownSelector/index.tsx +7 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@charcoal-ui/react",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.10.0-beta.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"@types/react": "^18.3.3",
|
|
30
30
|
"@types/react-dom": "^18.3.0",
|
|
31
31
|
"@types/react-router-dom": "^5.3.3",
|
|
32
|
-
"@types/warning": "^3.0.
|
|
32
|
+
"@types/warning": "^3.0.4",
|
|
33
33
|
"autoprefixer": "^10.4.19",
|
|
34
34
|
"jsdom": "^24.1.0",
|
|
35
35
|
"postcss-nested": "^7.0.2",
|
|
@@ -54,10 +54,10 @@
|
|
|
54
54
|
"react-compiler-runtime": "1.0.0",
|
|
55
55
|
"react-stately": "^3.26.0",
|
|
56
56
|
"warning": "^4.0.3",
|
|
57
|
-
"@charcoal-ui/
|
|
58
|
-
"@charcoal-ui/icons": "5.
|
|
59
|
-
"@charcoal-ui/
|
|
60
|
-
"@charcoal-ui/
|
|
57
|
+
"@charcoal-ui/theme": "5.10.0-beta.0",
|
|
58
|
+
"@charcoal-ui/icons": "5.10.0-beta.0",
|
|
59
|
+
"@charcoal-ui/utils": "5.10.0-beta.0",
|
|
60
|
+
"@charcoal-ui/foundation": "5.10.0-beta.0"
|
|
61
61
|
},
|
|
62
62
|
"peerDependencies": {
|
|
63
63
|
"react": ">=17.0.0"
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { render, screen } from '@testing-library/react'
|
|
2
|
+
import { vi } from 'vitest'
|
|
3
|
+
import DropdownSelector from '.'
|
|
4
|
+
import DropdownMenuItem from './DropdownMenuItem'
|
|
5
|
+
|
|
6
|
+
describe('DropdownSelector', () => {
|
|
7
|
+
describe('when `value` does not match any child `DropdownMenuItem`', () => {
|
|
8
|
+
it('keeps the DOM `<select>.value` aligned with props `value` without breaking placeholder display', () => {
|
|
9
|
+
const handleChange = vi.fn()
|
|
10
|
+
const { container } = render(
|
|
11
|
+
<DropdownSelector
|
|
12
|
+
label="Label"
|
|
13
|
+
value="missing-value"
|
|
14
|
+
placeholder="Select an option"
|
|
15
|
+
onChange={handleChange}
|
|
16
|
+
>
|
|
17
|
+
<DropdownMenuItem value="1">Option 1</DropdownMenuItem>
|
|
18
|
+
<DropdownMenuItem value="2">Option 2</DropdownMenuItem>
|
|
19
|
+
</DropdownSelector>,
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
const select = container.querySelector('select')
|
|
23
|
+
const button = screen.getByRole('button')
|
|
24
|
+
|
|
25
|
+
expect(select).not.toBeNull()
|
|
26
|
+
expect(select?.value).toBe('missing-value')
|
|
27
|
+
expect(button.textContent).toContain('Select an option')
|
|
28
|
+
})
|
|
29
|
+
})
|
|
30
|
+
})
|
|
@@ -50,6 +50,10 @@ export default function DropdownSelector({
|
|
|
50
50
|
)
|
|
51
51
|
|
|
52
52
|
const propsArray = getValuesRecursive(props.children)
|
|
53
|
+
const hasMatchedValue = useMemo(
|
|
54
|
+
() => propsArray.some((itemProps) => itemProps.value === props.value),
|
|
55
|
+
[propsArray, props.value],
|
|
56
|
+
)
|
|
53
57
|
|
|
54
58
|
const { visuallyHiddenProps } = useVisuallyHidden()
|
|
55
59
|
|
|
@@ -86,6 +90,9 @@ export default function DropdownSelector({
|
|
|
86
90
|
tabIndex={-1}
|
|
87
91
|
ref={selectRef}
|
|
88
92
|
>
|
|
93
|
+
{!hasMatchedValue && (
|
|
94
|
+
<option value={props.value}>{props.value}</option>
|
|
95
|
+
)}
|
|
89
96
|
{propsArray.map((itemProps) => {
|
|
90
97
|
return (
|
|
91
98
|
<option
|