11import * as React from "react" ;
2- import { useSafeLayoutEffect } from "ariakit-utils" ;
2+ import { useForkRef , useSafeLayoutEffect } from "ariakit-utils" ;
33
44import { getComponentProps , RenderProp , runIfFn , withIconA11y } from "../utils" ;
55
@@ -67,8 +67,16 @@ export const useSelectProps = ({
6767 uiProps = { ...uiProps , prefix : _prefix , suffix : _suffix } ;
6868
6969 const selectInlineStyles = React . useRef < Record < string , any > > ( { } ) ;
70- const prefixRef = React . useRef < HTMLElement > ( null ) ;
71- const suffixRef = React . useRef < HTMLElement > ( null ) ;
70+ let prefixRef = React . useRef < HTMLElement > ( null ) ;
71+ let suffixRef = React . useRef < HTMLElement > ( null ) ;
72+ prefixRef = useForkRef (
73+ prefixRef ,
74+ componentProps ?. prefixProps ?. ref ,
75+ ) as unknown as React . RefObject < HTMLElement > ;
76+ suffixRef = useForkRef (
77+ suffixRef ,
78+ componentProps ?. suffixProps ?. ref ,
79+ ) as unknown as React . RefObject < HTMLElement > ;
7280
7381 useSafeLayoutEffect ( ( ) => {
7482 let key = "" ;
@@ -94,38 +102,49 @@ export const useSelectProps = ({
94102 setHasPaddingCalculated ( true ) ;
95103 } , [ uiProps . prefix , uiProps . suffix ] ) ;
96104
97- const wrapperProps : SelectWrapperProps = {
98- ...uiProps ,
99- className,
100- style,
101- ...componentProps . wrapperProps ,
102- } ;
103-
104- const baseProps : SelectBaseProps = {
105- ...uiProps ,
106- disabled,
107- ...restProps ,
108- style : { ...selectInlineStyles . current } ,
109- children : finalChildren ,
110- ...componentProps . baseProps ,
111- } ;
105+ const wrapperProps : SelectWrapperProps = React . useMemo (
106+ ( ) => ( {
107+ ...uiProps ,
108+ className,
109+ style,
110+ ...componentProps . wrapperProps ,
111+ } ) ,
112+ [ className , componentProps . wrapperProps , style , uiProps ] ,
113+ ) ;
112114
113- const prefixProps : SelectPrefixProps = {
114- ...uiProps ,
115- disabled,
116- ...componentProps . prefixProps ,
117- ref : prefixRef ,
118- children : withIconA11y ( runIfFn ( uiProps . prefix , uiProps ) ) ,
119- } ;
115+ const baseProps : SelectBaseProps = React . useMemo (
116+ ( ) => ( {
117+ ...uiProps ,
118+ disabled,
119+ ...restProps ,
120+ style : { ...selectInlineStyles . current } ,
121+ ...componentProps . baseProps ,
122+ children : finalChildren ,
123+ } ) ,
124+ [ componentProps . baseProps , disabled , finalChildren , restProps , uiProps ] ,
125+ ) ;
120126
121- const suffixProps : SelectSuffixProps = {
122- ...uiProps ,
123- disabled,
124- ...componentProps . suffixProps ,
125- ref : suffixRef ,
126- children : uiProps . suffix ,
127- } ;
127+ const prefixProps : SelectPrefixProps = React . useMemo (
128+ ( ) => ( {
129+ ...uiProps ,
130+ disabled,
131+ ...componentProps . prefixProps ,
132+ ref : prefixRef ,
133+ children : withIconA11y ( runIfFn ( uiProps . prefix , uiProps ) ) ,
134+ } ) ,
135+ [ componentProps . prefixProps , disabled , uiProps ] ,
136+ ) ;
128137
138+ const suffixProps : SelectSuffixProps = React . useMemo (
139+ ( ) => ( {
140+ ...uiProps ,
141+ disabled,
142+ ...componentProps . suffixProps ,
143+ ref : suffixRef ,
144+ children : uiProps . suffix ,
145+ } ) ,
146+ [ componentProps . suffixProps , disabled , uiProps ] ,
147+ ) ;
129148 return {
130149 uiProps,
131150 wrapperProps,
0 commit comments