@@ -30,6 +30,7 @@ const defaultAriaStrings = {
3030interface ComboBoxFieldProps extends Pick < FieldProps , 'description' | 'errorMessage' | 'leadingIcon' > {
3131 label : string ;
3232 placeholder ?: string ;
33+ hideClearButton ?: boolean ;
3334 /**
3435 * If your project supports multiple languages,
3536 * it is recommended to pass translated labels to these properties
@@ -50,7 +51,7 @@ interface ComboBoxProps<T extends Record<string, unknown>>
5051}
5152
5253const ComboBoxInput = React . forwardRef < HTMLDivElement , ComboBoxFieldProps > (
53- ( { label, placeholder, leadingIcon, ariaStrings, inputRef : externalInputRef } , forwardedRef ) => {
54+ ( { label, placeholder, leadingIcon, ariaStrings, hideClearButton , inputRef : externalInputRef } , forwardedRef ) => {
5455 const state = React . useContext ( ComboBoxStateContext ) ;
5556 const internalInputRef = React . useRef < HTMLInputElement > ( null ) ;
5657
@@ -67,7 +68,7 @@ const ComboBoxInput = React.forwardRef<HTMLDivElement, ComboBoxFieldProps>(
6768 < Label $flying = { Boolean ( placeholder || state ?. inputValue ?. length > 0 ) } > { label } </ Label >
6869 < Input placeholder = { placeholder } ref = { combinedInputRef } />
6970 </ InnerWrapper >
70- { state ?. inputValue ?. length > 0 ? (
71+ { ! hideClearButton && state ?. inputValue ?. length > 0 ? (
7172 < Button
7273 // Don't inherit default Button behavior from ComboBox.
7374 slot = { null }
@@ -79,7 +80,7 @@ const ComboBoxInput = React.forwardRef<HTMLDivElement, ComboBoxFieldProps>(
7980 >
8081 < XCrossCircleIcon />
8182 </ Button >
82- ) : (
83+ ) : state ?. inputValue ?. length > 0 ? null : (
8384 < VisuallyHidden aria-live = "polite" > { ariaStrings . messageFieldIsCleared } </ VisuallyHidden >
8485 ) }
8586 </ FakeInput >
@@ -96,6 +97,7 @@ function ComboBoxComponent<T extends Record<string, unknown>>(
9697 children,
9798 placeholder,
9899 leadingIcon,
100+ hideClearButton,
99101 ariaStrings = defaultAriaStrings ,
100102 errorMessage,
101103 description,
@@ -130,6 +132,7 @@ function ComboBoxComponent<T extends Record<string, unknown>>(
130132 label = { label }
131133 placeholder = { placeholder }
132134 leadingIcon = { leadingIcon }
135+ hideClearButton = { hideClearButton }
133136 ariaStrings = { ariaStrings }
134137 />
135138 < Footer > { isInvalid ? < FieldError > { errorMessage } </ FieldError > : description } </ Footer >
0 commit comments