11import clsx from 'classnames' ;
2- import type { FC , ReactElement , ReactNode } from 'react' ;
2+ import type { ReactElement , ReactNode } from 'react' ;
33import React , { cloneElement , useRef } from 'react' ;
44import type { BaseInputProps } from './interface' ;
55import { hasAddon , hasPrefixSuffix } from './utils/commonUtils' ;
66
7- const BaseInput : FC < BaseInputProps > = ( props ) => {
7+ export interface HolderRef {
8+ /** Provider holder ref. Will return `null` if not wrap anything */
9+ nativeElement : HTMLElement | null ;
10+ }
11+
12+ const BaseInput = React . forwardRef < HolderRef , BaseInputProps > ( ( props , ref ) => {
813 const {
914 inputElement : inputEl ,
1015 children,
@@ -54,6 +59,13 @@ const BaseInput: FC<BaseInputProps> = (props) => {
5459 null ,
5560 } ) ;
5661
62+ // ======================== Ref ======================== //
63+ const groupRef = useRef < HTMLDivElement > ( null ) ;
64+
65+ React . useImperativeHandle ( ref , ( ) => ( {
66+ nativeElement : groupRef . current || containerRef . current ,
67+ } ) ) ;
68+
5769 // ================== Prefix & Suffix ================== //
5870 if ( hasAffix ) {
5971 // ================== Clear Icon ================== //
@@ -157,7 +169,7 @@ const BaseInput: FC<BaseInputProps> = (props) => {
157169 // Need another wrapper for changing display:table to display:inline-block
158170 // and put style prop in wrapper
159171 element = (
160- < GroupWrapperComponent className = { mergedGroupClassName } >
172+ < GroupWrapperComponent className = { mergedGroupClassName } ref = { groupRef } >
161173 < WrapperComponent className = { mergedWrapperClassName } >
162174 { addonBefore && (
163175 < GroupAddonComponent className = { addonCls } >
@@ -184,6 +196,6 @@ const BaseInput: FC<BaseInputProps> = (props) => {
184196 } ,
185197 hidden,
186198 } ) ;
187- } ;
199+ } ) ;
188200
189201export default BaseInput ;
0 commit comments