Skip to content

Commit 64842c0

Browse files
authored
fix(SearchInput): advanced search aria-expanded set by default (#11494)
* fix(SearchInput): advanced search aria-expanded set by default * update unit tests
1 parent e71da5e commit 64842c0

3 files changed

Lines changed: 24 additions & 19 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ const SearchInputBase: React.FunctionComponent<SearchInputProps> = ({
140140
onSearch,
141141
onClear,
142142
onToggleAdvancedSearch,
143-
isAdvancedSearchOpen,
143+
isAdvancedSearchOpen = false,
144144
resultsCount,
145145
onNextClick,
146146
onPreviousClick,

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

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ describe('SearchInput', () => {
105105
onClear={props.onClear}
106106
/>
107107
);
108+
const expandButton = screen.getByRole('button', { name: 'Open advanced search' });
109+
expect(expandButton).toHaveAttribute('aria-expanded', 'false');
108110

109111
await user.click(screen.getByRole('button', { name: 'Search' }));
110112

@@ -139,7 +141,12 @@ describe('SearchInput', () => {
139141

140142
await user.click(screen.getByRole('button', { name: 'Search' }));
141143

142-
await user.click(screen.getByRole('button', { name: 'Open advanced search' }));
144+
const expandButton = screen.getByRole('button', { name: 'Open advanced search' });
145+
expect(expandButton).toHaveAttribute('aria-expanded', 'false');
146+
147+
await user.click(expandButton);
148+
expect(expandButton).toHaveAttribute('aria-expanded', 'true');
149+
143150
expect(screen.getByTestId('test-id')).toContainElement(screen.getByText('First name'));
144151

145152
expect(props.onSearch).toHaveBeenCalled();
@@ -149,7 +156,14 @@ describe('SearchInput', () => {
149156
test('advanced search with custom attributes and appendTo="inline', async () => {
150157
const user = userEvent.setup();
151158

152-
render(<SearchInput data-testid="test-id" attributes={[{ attr: 'test', display: 'test' }]} appendTo="inline" />);
159+
render(
160+
<SearchInput
161+
data-testid="test-id"
162+
attributes={[{ attr: 'test', display: 'test' }]}
163+
advancedSearchDelimiter=":"
164+
appendTo="inline"
165+
/>
166+
);
153167

154168
await user.click(screen.getByRole('button', { name: 'Open advanced search' }));
155169

@@ -160,7 +174,12 @@ describe('SearchInput', () => {
160174
const user = userEvent.setup();
161175

162176
render(
163-
<SearchInput data-testid="test-id" attributes={[{ attr: 'test', display: 'test' }]} appendTo={document.body} />
177+
<SearchInput
178+
data-testid="test-id"
179+
attributes={[{ attr: 'test', display: 'test' }]}
180+
advancedSearchDelimiter=":"
181+
appendTo={document.body}
182+
/>
164183
);
165184

166185
await user.click(screen.getByRole('button', { name: 'Open advanced search' }));

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

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,6 @@ exports[`SearchInput advanced search 1`] = `
138138
</button>
139139
</div>
140140
</div>
141-
<div
142-
class=""
143-
data-popper-escaped="true"
144-
data-popper-placement="bottom-start"
145-
data-popper-reference-hidden="true"
146-
style="position: absolute; left: 0px; top: 0px; z-index: 9999; opacity: 0; transition: opacity 0ms cubic-bezier(.54, 1.5, .38, 1.11); min-width: 0px; transform: translate(0px, 0px);"
147-
/>
148141
</div>
149142
</DocumentFragment>
150143
`;
@@ -293,7 +286,7 @@ exports[`SearchInput advanced search with custom attributes 1`] = `
293286
data-popper-escaped="true"
294287
data-popper-placement="bottom-start"
295288
data-popper-reference-hidden="true"
296-
style="position: absolute; top: 0px; left: 0px; transform: translate(0px, 0px); min-width: 0px; z-index: 9999; opacity: 1; transition: opacity 0ms cubic-bezier(.54, 1.5, .38, 1.11);"
289+
style="position: absolute; left: 0px; top: 0px; z-index: 9999; opacity: 1; transition: opacity 0ms cubic-bezier(.54, 1.5, .38, 1.11); min-width: 0px; transform: translate(0px, 0px);"
297290
>
298291
<div
299292
class="pf-v6-c-panel pf-m-raised"
@@ -621,13 +614,6 @@ exports[`SearchInput renders search input in strict mode 1`] = `
621614
</button>
622615
</div>
623616
</div>
624-
<div
625-
class=""
626-
data-popper-escaped="true"
627-
data-popper-placement="bottom-start"
628-
data-popper-reference-hidden="true"
629-
style="position: absolute; left: 0px; top: 0px; z-index: 9999; opacity: 0; transition: opacity 0ms cubic-bezier(.54, 1.5, .38, 1.11); min-width: 0px; transform: translate(0px, 0px);"
630-
/>
631617
</div>
632618
</DocumentFragment>
633619
`;

0 commit comments

Comments
 (0)