@charcoal-ui/react 5.6.0-beta.3 → 5.6.0-beta.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@charcoal-ui/react",
3
- "version": "5.6.0-beta.3",
3
+ "version": "5.6.0-beta.5",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -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/foundation": "5.6.0-beta.3",
58
- "@charcoal-ui/theme": "5.6.0-beta.3",
59
- "@charcoal-ui/icons": "5.6.0-beta.3",
60
- "@charcoal-ui/utils": "5.6.0-beta.3"
57
+ "@charcoal-ui/foundation": "5.6.0-beta.5",
58
+ "@charcoal-ui/icons": "5.6.0-beta.5",
59
+ "@charcoal-ui/utils": "5.6.0-beta.5",
60
+ "@charcoal-ui/theme": "5.6.0-beta.5"
61
61
  },
62
62
  "peerDependencies": {
63
63
  "react": ">=17.0.0"
@@ -1,4 +1,4 @@
1
- import { useState } from 'react'
1
+ import { useRef, useState } from 'react'
2
2
  import DropdownSelector from '.'
3
3
  import { Divider } from './Divider'
4
4
  import MenuItemGroup from './MenuItemGroup'
@@ -453,3 +453,44 @@ export const WithSeconday: StoryObj<typeof DropdownSelector> = {
453
453
  )
454
454
  },
455
455
  }
456
+
457
+ export const WithRef: StoryObj<typeof DropdownSelector> = {
458
+ render: function Render(props) {
459
+ const [selected, setSelected] = useState('1')
460
+ const [currentValue, setCurrentValue] = useState('')
461
+ const selectRef = useRef<HTMLSelectElement>(null)
462
+
463
+ return (
464
+ <div
465
+ style={{
466
+ width: 288,
467
+ display: 'flex',
468
+ flexDirection: 'column',
469
+ gap: 16,
470
+ }}
471
+ >
472
+ <DropdownSelector
473
+ {...props}
474
+ onChange={(value) => {
475
+ setSelected(value)
476
+ }}
477
+ value={selected}
478
+ label="label"
479
+ selectRef={selectRef}
480
+ >
481
+ <DropdownMenuItem value="1">Option 1</DropdownMenuItem>
482
+ <DropdownMenuItem value="2">Option 2</DropdownMenuItem>
483
+ <DropdownMenuItem value="3">Option 3</DropdownMenuItem>
484
+ </DropdownSelector>
485
+ <Button
486
+ onClick={() => {
487
+ setCurrentValue(selectRef.current?.value ?? 'ref is null')
488
+ }}
489
+ >
490
+ check ref current value
491
+ </Button>
492
+ <div>ref current value: {currentValue}</div>
493
+ </div>
494
+ )
495
+ },
496
+ }
@@ -31,11 +31,13 @@ export type DropdownSelectorProps = {
31
31
  children: MenuListChildren
32
32
  onChange: (value: string) => void
33
33
  className?: string
34
+ selectRef?: React.Ref<HTMLSelectElement>
34
35
  } & Pick<PopoverProps, 'inertWorkaround'>
35
36
 
36
37
  export default function DropdownSelector({
37
38
  onChange,
38
39
  showLabel = false,
40
+ selectRef,
39
41
  ...props
40
42
  }: DropdownSelectorProps) {
41
43
  const triggerRef = useRef<HTMLButtonElement>(null)
@@ -82,6 +84,7 @@ export default function DropdownSelector({
82
84
  value={props.value}
83
85
  onChange={handleChange}
84
86
  tabIndex={-1}
87
+ ref={selectRef}
85
88
  >
86
89
  {propsArray.map((itemProps) => {
87
90
  return (