Skip to content

Commit

Permalink
Merge pull request #58 from bobbychan/fix/select
Browse files Browse the repository at this point in the history
fix: add select ref
  • Loading branch information
bobbychan authored Dec 12, 2023
2 parents f9fc402 + a2202da commit 28fa9de
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/gold-poems-smile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@alice-ui/react': patch
---

fix select ref
12 changes: 9 additions & 3 deletions packages/react/src/select/select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { ChevronDownIcon } from '@alice-ui/icons';
import { clsx } from '@alice-ui/shared-utils';
import { SelectSlots, SelectVariantProps, SlotsToClasses, select } from '@alice-ui/theme';
import { ReactElement, ReactNode, cloneElement, useMemo } from 'react';
import { ForwardedRef, ReactElement, ReactNode, cloneElement, forwardRef, useMemo } from 'react';
import type { Placement } from 'react-aria';
import type { SelectProps as AriaSelectProps, PopoverProps } from 'react-aria-components';
import {
Expand Down Expand Up @@ -63,7 +63,7 @@ export interface SelectProps<T extends object>
classNames?: SlotsToClasses<SelectSlots>;
}

export function Select<T extends object>(props: SelectProps<T>) {
function Select<T extends object>(props: SelectProps<T>, ref: ForwardedRef<HTMLDivElement>) {
const {
children,
className,
Expand Down Expand Up @@ -114,7 +114,7 @@ export function Select<T extends object>(props: SelectProps<T>) {
}, [isLoading, clonedIcon, spinnerProps, slots, classNames?.spinner]);

return (
<AriaSelect className={slots.base({ class: baseStyles })} {...otherProps}>
<AriaSelect ref={ref} className={slots.base({ class: baseStyles })} {...otherProps}>
{label && <Label className={slots.label({ class: classNames?.label })}>{label}</Label>}
<div className={slots.mainWrapper({ class: classNames?.mainWrapper })}>
<Button className={slots.trigger({ class: classNames?.trigger })}>
Expand Down Expand Up @@ -152,3 +152,9 @@ export function Select<T extends object>(props: SelectProps<T>) {
</AriaSelect>
);
}

const _Select = forwardRef(Select) as <T extends object>(
props: SelectProps<T> & { ref?: ForwardedRef<HTMLDivElement> },
) => ReactElement;

export { _Select as Select };

0 comments on commit 28fa9de

Please sign in to comment.