Skip to content

Commit 1c787a8

Browse files
fix(SearchInput): allowed spreading of props to input element (#11540)
1 parent 7fb9ea7 commit 1c787a8

File tree

4 files changed

+18
-0
lines changed

4 files changed

+18
-0
lines changed

packages/react-core/src/components/SearchInput/SearchInput.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ export interface SearchInputProps extends Omit<React.HTMLProps<HTMLDivElement>,
124124
value?: string;
125125
/** Name attribue for the search input */
126126
name?: string;
127+
/** Additional props to spread to the search input element. */
128+
inputProps?: any;
127129
}
128130

129131
const SearchInputBase: React.FunctionComponent<SearchInputProps> = ({
@@ -159,6 +161,7 @@ const SearchInputBase: React.FunctionComponent<SearchInputProps> = ({
159161
zIndex = 9999,
160162
name,
161163
areUtilitiesDisplayed,
164+
inputProps,
162165
...props
163166
}: SearchInputProps) => {
164167
const [isSearchMenuOpen, setIsSearchMenuOpen] = React.useState(false);
@@ -302,6 +305,7 @@ const SearchInputBase: React.FunctionComponent<SearchInputProps> = ({
302305
onChange={onChangeHandler}
303306
name={name}
304307
inputId={searchInputId}
308+
inputProps={inputProps}
305309
/>
306310
{(renderUtilities || areUtilitiesDisplayed) && (
307311
<TextInputGroupUtilities>

packages/react-core/src/components/SearchInput/__tests__/SearchInput.test.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,3 +275,8 @@ test('Utilities are rendered when areUtilitiesDisplayed is set', () => {
275275
render(<SearchInput {...props} areUtilitiesDisplayed resetButtonLabel="test-util-display" />);
276276
expect(screen.getByLabelText('test-util-display')).toBeVisible();
277277
});
278+
279+
test('Additional props are spread when inputProps prop is passed', () => {
280+
render(<SearchInput aria-label="Test input" inputProps={{ autofocus: 'true' }} />);
281+
expect(screen.getByLabelText('Test input')).toHaveAttribute('autofocus', 'true');
282+
});

packages/react-core/src/components/TextInputGroup/TextInputGroupMain.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ export interface TextInputGroupMainProps extends Omit<React.HTMLProps<HTMLDivEle
5757
'aria-controls'?: string;
5858
/** The id of the input element */
5959
inputId?: string;
60+
/** Additional props to spread to the input element. */
61+
inputProps?: any;
6062
}
6163

6264
const TextInputGroupMainBase: React.FunctionComponent<TextInputGroupMainProps> = ({
@@ -78,6 +80,7 @@ const TextInputGroupMainBase: React.FunctionComponent<TextInputGroupMainProps> =
7880
isExpanded,
7981
'aria-controls': ariaControls,
8082
inputId,
83+
inputProps,
8184
...props
8285
}: TextInputGroupMainProps) => {
8386
const { isDisabled, validated } = React.useContext(TextInputGroupContext);
@@ -121,6 +124,7 @@ const TextInputGroupMainBase: React.FunctionComponent<TextInputGroupMainProps> =
121124
{...(role && { role })}
122125
{...(isExpanded !== undefined && { 'aria-expanded': isExpanded })}
123126
{...(ariaControls && { 'aria-controls': ariaControls })}
127+
{...inputProps}
124128
/>
125129
{validated && <TextInputGroupIcon isStatus>{<StatusIcon />}</TextInputGroupIcon>}
126130
</span>

packages/react-core/src/components/TextInputGroup/__tests__/TextInputGroupMain.test.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,11 @@ describe('TextInputGroupMain', () => {
317317
expect(onBlurMock).toHaveBeenCalledTimes(1);
318318
});
319319

320+
test('Additional props are spread when inputProps prop is passed', () => {
321+
render(<TextInputGroupMain aria-label="Test input" inputProps={{ autofocus: 'true' }} />);
322+
expect(screen.getByLabelText('Test input')).toHaveAttribute('autofocus', 'true');
323+
});
324+
320325
it('matches the snapshot', () => {
321326
const { asFragment } = render(<TextInputGroupMain>Test</TextInputGroupMain>);
322327

0 commit comments

Comments
 (0)