Skip to content

Commit 7552af9

Browse files
authored
fix(Search): use native input type="search" (#20415)
* fix(search): use native input type=search instead of text with role * fix(search): remove default browser decoration * fix(Search): update stories to use type=search and remove role prop * refactor(Search): deprecate role prop and remove type from stories * chore(search): clean up redundant comment * chore(search): use deprecate util for role prop * chore: update snapshots
1 parent c2395b4 commit 7552af9

File tree

6 files changed

+32
-33
lines changed

6 files changed

+32
-33
lines changed

packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3421,9 +3421,7 @@ Map {
34213421
],
34223422
"type": "oneOfType",
34233423
},
3424-
"role": {
3425-
"type": "string",
3426-
},
3424+
"role": [Function],
34273425
"size": {
34283426
"args": [
34293427
[
@@ -7299,9 +7297,7 @@ Map {
72997297
],
73007298
"type": "oneOfType",
73017299
},
7302-
"role": {
7303-
"type": "string",
7304-
},
7300+
"role": [Function],
73057301
"size": {
73067302
"args": [
73077303
[

packages/react/src/components/DataTable/__tests__/__snapshots__/DataTable-test.js.snap

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Jest Snapshot v1, https://goo.gl/fbAQLP
1+
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
22

33
exports[`DataTable behaves as expected selection -- radio buttons should not have select-all checkbox 1`] = `
44
<div>
@@ -532,9 +532,8 @@ exports[`DataTable behaves as expected selection should render and match snapsho
532532
class="cds--search-input"
533533
id="custom-id"
534534
placeholder="Filter table"
535-
role="searchbox"
536535
tabindex="0"
537-
type="text"
536+
type="search"
538537
value=""
539538
/>
540539
<button
@@ -965,9 +964,8 @@ exports[`DataTable renders as expected - Component API should render and match s
965964
class="cds--search-input"
966965
id="custom-id"
967966
placeholder="Filter table"
968-
role="searchbox"
969967
tabindex="0"
970-
type="text"
968+
type="search"
971969
value=""
972970
/>
973971
<button

packages/react/src/components/DataTable/__tests__/__snapshots__/TableToolbarSearch-test.js.snap

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Jest Snapshot v1, https://goo.gl/fbAQLP
1+
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
22

33
exports[`TableToolbarSearch renders as expected - Component API should render 1`] = `
44
<div>
@@ -39,9 +39,8 @@ exports[`TableToolbarSearch renders as expected - Component API should render 1`
3939
class="cds--search-input"
4040
id="custom-id"
4141
placeholder="Filter table"
42-
role="searchbox"
4342
tabindex="0"
44-
type="text"
43+
type="search"
4544
value=""
4645
/>
4746
<button

packages/react/src/components/Search/Search.stories.js

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright IBM Corp. 2016, 2023
2+
* Copyright IBM Corp. 2016, 2025
33
*
44
* This source code is licensed under the Apache-2.0 license found in the
55
* LICENSE file in the root directory of this source tree.
@@ -110,9 +110,8 @@ Default.args = {
110110
disabled: false,
111111
labelText: 'Label text',
112112
placeholder: 'Placeholder text',
113-
role: 'searchbox',
114113
size: 'md',
115-
type: 'text',
114+
type: 'search',
116115
};
117116

118117
Default.argTypes = {
@@ -157,20 +156,10 @@ Default.argTypes = {
157156
renderIcon: {
158157
control: false,
159158
},
160-
role: {
161-
control: {
162-
type: 'text',
163-
},
164-
},
165159
size: {
166160
options: ['sm', 'md', 'lg'],
167161
control: {
168162
type: 'select',
169163
},
170164
},
171-
type: {
172-
control: {
173-
type: 'text',
174-
},
175-
},
176165
};

packages/react/src/components/Search/Search.tsx

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,9 @@ export interface SearchProps extends InputPropsBase {
102102
renderIcon?: ComponentType | FunctionComponent;
103103

104104
/**
105-
* Specify the role for the underlying `<input>`, defaults to `searchbox`
105+
* @deprecated Specify the role for the underlying `<input>`.
106+
* No longer needed since `<input type="search">` already provides the correct semantics.
107+
* This prop will be removed in the next major release of Carbon.
106108
*/
107109
role?: string;
108110

@@ -112,7 +114,7 @@ export interface SearchProps extends InputPropsBase {
112114
size?: 'sm' | 'md' | 'lg';
113115

114116
/**
115-
* Optional prop to specify the type of the `<input>`
117+
* Specify the type of the `<input>`
116118
*/
117119
type?: string;
118120

@@ -141,9 +143,9 @@ const Search = React.forwardRef<HTMLInputElement, SearchProps>(
141143
onExpand,
142144
placeholder = 'Search',
143145
renderIcon,
144-
role = 'searchbox',
146+
role,
145147
size = 'md',
146-
type = 'text',
148+
type = 'search',
147149
value,
148150
...rest
149151
},
@@ -383,16 +385,22 @@ Search.propTypes = {
383385
renderIcon: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
384386

385387
/**
388+
* Deprecated, since <input type="search"> already provides correct semantics.
386389
* Specify the role for the underlying `<input>`, defaults to `searchbox`
387390
*/
388-
role: PropTypes.string,
391+
role: deprecate(
392+
PropTypes.string,
393+
'The `role` prop has been deprecated since <input type="search"> already provides correct semantics. ' +
394+
'It will be removed in the next major release of Carbon.'
395+
),
389396

390397
/**
391398
* Specify the size of the Search
392399
*/
393400
size: PropTypes.oneOf(['sm', 'md', 'lg']),
401+
394402
/**
395-
* Optional prop to specify the type of the `<input>`
403+
* Specify the type of the `<input>`
396404
*/
397405
type: PropTypes.string,
398406

packages/styles/scss/components/search/_search.scss

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,15 @@
6868
&::-ms-clear {
6969
display: none;
7070
}
71+
72+
&::-webkit-search-decoration,
73+
&::-webkit-search-cancel-button,
74+
&::-webkit-search-results-button,
75+
&::-webkit-search-results-decoration {
76+
display: none;
77+
-webkit-appearance: none;
78+
appearance: none;
79+
}
7180
}
7281

7382
.#{$prefix}--search-input[disabled] {

0 commit comments

Comments
 (0)