Skip to content

Commit fbf975c

Browse files
committed
fix(search): ExpandableSearch: collapsed-state tooltip label is hardcoded "Search" with no way to override it
1 parent f5631b6 commit fbf975c

4 files changed

Lines changed: 69 additions & 2 deletions

File tree

packages/react/src/components/ExpandableSearch/ExpandableSearch-test.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,4 +206,29 @@ describe('ExpandableSearch', () => {
206206
);
207207
});
208208
});
209+
210+
describe('expandButtonLabelText', () => {
211+
it('renders the custom label on the collapsed tooltip', () => {
212+
const { container } = render(
213+
<ExpandableSearch
214+
labelText="test-search"
215+
expandButtonLabelText="Suche"
216+
/>
217+
);
218+
219+
expect(
220+
container.querySelector('.cds--tooltip-content')
221+
).toHaveTextContent('Suche');
222+
});
223+
224+
it('defaults to "Search" when expandButtonLabelText is not provided', () => {
225+
const { container } = render(
226+
<ExpandableSearch labelText="test-search" />
227+
);
228+
229+
expect(
230+
container.querySelector('.cds--tooltip-content')
231+
).toHaveTextContent('Search');
232+
});
233+
});
209234
});

packages/react/src/components/Search/Search-test.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,35 @@ describe('Search', () => {
165165
expect(onExpand).toHaveBeenCalledTimes(3);
166166
});
167167

168+
it('should respect expandButtonLabelText prop', () => {
169+
const { container } = render(
170+
<Search
171+
labelText="test-search"
172+
onExpand={() => {}}
173+
isExpanded={false}
174+
expandButtonLabelText="Suche"
175+
/>
176+
);
177+
178+
expect(
179+
container.querySelector('.cds--tooltip-content')
180+
).toHaveTextContent('Suche');
181+
});
182+
183+
it('should default expandButtonLabelText to "Search"', () => {
184+
const { container } = render(
185+
<Search
186+
labelText="test-search"
187+
onExpand={() => {}}
188+
isExpanded={false}
189+
/>
190+
);
191+
192+
expect(
193+
container.querySelector('.cds--tooltip-content')
194+
).toHaveTextContent('Search');
195+
});
196+
168197
it('should call onKeyDown when expected', async () => {
169198
const onKeyDown = jest.fn();
170199
render(<Search labelText="test-search" onKeyDown={onKeyDown} />);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export default {
8888

8989
const defaultParameters = {
9090
controls: {
91-
exclude: ['isExpanded', 'renderIcon', 'role'],
91+
exclude: ['isExpanded', 'renderIcon', 'role', 'expandButtonLabelText'],
9292
},
9393
};
9494

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ export interface SearchProps extends InputPropsBase {
4949
*/
5050
closeButtonLabelText?: string;
5151

52+
/**
53+
* Specify the label for the expand button in ExpandableSearch (collapsed state tooltip).
54+
* Use this prop to provide a localised string in place of the default "Search" label.
55+
*/
56+
expandButtonLabelText?: string;
57+
5258
/**
5359
* Optionally provide the default value of the `<input>`
5460
*/
@@ -132,6 +138,7 @@ const Search = React.forwardRef<HTMLInputElement, SearchProps>(
132138
autoComplete = 'off',
133139
className,
134140
closeButtonLabelText = 'Clear search input',
141+
expandButtonLabelText = 'Search',
135142
defaultValue,
136143
disabled,
137144
isExpanded = true,
@@ -277,7 +284,7 @@ const Search = React.forwardRef<HTMLInputElement, SearchProps>(
277284
<Tooltip
278285
className={`${prefix}--search-tooltip ${prefix}--search-magnifier-tooltip ${prefix}--icon-tooltip`}
279286
align="top"
280-
label="Search">
287+
label={expandButtonLabelText}>
281288
{magnifierButton}
282289
</Tooltip>
283290
) : (
@@ -342,6 +349,12 @@ Search.propTypes = {
342349
*/
343350
closeButtonLabelText: PropTypes.string,
344351

352+
/**
353+
* Specify the label for the expand button in ExpandableSearch (collapsed state tooltip).
354+
* Use this prop to provide a localised string in place of the default "Search" label.
355+
*/
356+
expandButtonLabelText: PropTypes.string,
357+
345358
/**
346359
* Optionally provide the default value of the `<input>`
347360
*/

0 commit comments

Comments
 (0)