@charcoal-ui/react 5.6.0-beta.4 → 5.6.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@charcoal-ui/react",
3
- "version": "5.6.0-beta.4",
3
+ "version": "5.6.0",
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.4",
58
- "@charcoal-ui/icons": "5.6.0-beta.4",
59
- "@charcoal-ui/theme": "5.6.0-beta.4",
60
- "@charcoal-ui/utils": "5.6.0-beta.4"
57
+ "@charcoal-ui/icons": "5.6.0",
58
+ "@charcoal-ui/foundation": "5.6.0",
59
+ "@charcoal-ui/utils": "5.6.0",
60
+ "@charcoal-ui/theme": "5.6.0"
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 (
@@ -2,7 +2,7 @@ import './index.css'
2
2
 
3
3
  import { usePaginationWindow } from './helper'
4
4
  import { useClassNames } from '../../_lib/useClassNames'
5
- import IconButton from '../IconButton'
5
+ import IconButton, { IconButtonProps } from '../IconButton'
6
6
  import {
7
7
  PaginationContext,
8
8
  usePaginationContext,
@@ -14,9 +14,10 @@ import {
14
14
 
15
15
  type NavButtonProps = {
16
16
  direction: 'prev' | 'next'
17
+ ariaLabel: IconButtonProps['aria-label']
17
18
  }
18
19
 
19
- function NavButton({ direction }: NavButtonProps) {
20
+ function NavButton({ direction, ariaLabel }: NavButtonProps) {
20
21
  'use memo'
21
22
  const {
22
23
  page,
@@ -44,6 +45,7 @@ function NavButton({ direction }: NavButtonProps) {
44
45
  icon={isPrev ? '24/Prev' : '24/Next'}
45
46
  size={size}
46
47
  hidden={disabled}
48
+ aria-label={ariaLabel}
47
49
  {...(isLinkMode && makeUrl
48
50
  ? {
49
51
  component: LinkComponent as 'a',
@@ -122,11 +124,13 @@ function PageItem({ value }: { value: number | string }) {
122
124
  )
123
125
  }
124
126
 
125
- interface CommonProps {
127
+ interface PaginationCommonProps {
126
128
  page: number
127
129
  pageCount: number
128
130
  pageRangeDisplayed?: PageRangeDisplayed
129
131
  size?: Size
132
+ ariaLabelPrev?: string
133
+ ariaLabelNext?: string
130
134
  }
131
135
 
132
136
  type NavProps = Omit<React.ComponentPropsWithoutRef<'nav'>, 'onChange'>
@@ -150,29 +154,33 @@ type NavProps = Omit<React.ComponentPropsWithoutRef<'nav'>, 'onChange'>
150
154
  * // Link mode with linkProps (e.g. Next.js scroll)
151
155
  * <Pagination page={1} pageCount={10} makeUrl={(p) => `?page=${p}`} component={Link} linkProps={{ scroll: 'marker' }} />
152
156
  */
153
- export type PaginationProps<T extends React.ElementType = 'a'> = CommonProps &
154
- NavProps &
155
- (
156
- | {
157
- onChange(newPage: number): void
158
- makeUrl?: never
159
- component?: never
160
- linkProps?: undefined
161
- }
162
- | {
163
- makeUrl(page: number): string
164
- onChange?: never
165
- /**
166
- * The component used for link elements. Receives `href`, `className`, and `children`.
167
- * @default 'a'
168
- */
169
- component?: T
170
- /**
171
- * Additional props passed to all link elements (e.g. Next.js Link's scroll, prefetch).
172
- */
173
- linkProps?: Omit<React.ComponentPropsWithoutRef<T>, 'href' | 'children'>
174
- }
175
- )
157
+ export type PaginationProps<T extends React.ElementType = 'a'> =
158
+ PaginationCommonProps &
159
+ NavProps &
160
+ (
161
+ | {
162
+ onChange(newPage: number): void
163
+ makeUrl?: never
164
+ component?: never
165
+ linkProps?: undefined
166
+ }
167
+ | {
168
+ makeUrl(page: number): string
169
+ onChange?: never
170
+ /**
171
+ * The component used for link elements. Receives `href`, `className`, and `children`.
172
+ * @default 'a'
173
+ */
174
+ component?: T
175
+ /**
176
+ * Additional props passed to all link elements (e.g. Next.js Link's scroll, prefetch).
177
+ */
178
+ linkProps?: Omit<
179
+ React.ComponentPropsWithoutRef<T>,
180
+ 'href' | 'children'
181
+ >
182
+ }
183
+ )
176
184
 
177
185
  export default function Pagination<T extends React.ElementType = 'a'>({
178
186
  page,
@@ -184,6 +192,8 @@ export default function Pagination<T extends React.ElementType = 'a'>({
184
192
  component: LinkComponent = 'a' as T,
185
193
  linkProps,
186
194
  className,
195
+ ariaLabelNext = 'Next',
196
+ ariaLabelPrev = 'Previous',
187
197
  ...navProps
188
198
  }: PaginationProps<T>) {
189
199
  'use memo'
@@ -217,11 +227,11 @@ export default function Pagination<T extends React.ElementType = 'a'>({
217
227
  {...navProps}
218
228
  className={classNames}
219
229
  >
220
- <NavButton direction="prev" />
230
+ <NavButton direction="prev" ariaLabel={ariaLabelPrev} />
221
231
  {window.map((p) => (
222
232
  <PageItem key={p} value={p} />
223
233
  ))}
224
- <NavButton direction="next" />
234
+ <NavButton direction="next" ariaLabel={ariaLabelNext} />
225
235
  </nav>
226
236
  </PaginationContext.Provider>
227
237
  )