Skip to content

Commit 9c785af

Browse files
authored
fix(examples): make sure examples with SearchInput have onClear (#12044)
* fix(examples): make sure examples with SearchInput have onClear Signed-off-by: gitdallas <[email protected]> * stop propagation in instances of onclear closing menus Signed-off-by: gitdallas <[email protected]> --------- Signed-off-by: gitdallas <[email protected]>
1 parent 1127a29 commit 9c785af

File tree

9 files changed

+54
-11
lines changed

9 files changed

+54
-11
lines changed

packages/react-core/src/components/Menu/examples/MenuFilterDrilldown.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ export const MenuWithDrilldown: React.FunctionComponent = () => {
110110
value={startInput}
111111
aria-label="Filter menu items"
112112
onChange={(_event, value) => handleStartTextInputChange(value)}
113+
onClear={() => handleStartTextInputChange('')}
113114
/>
114115
</MenuSearchInput>
115116
</MenuSearch>

packages/react-core/src/components/Menu/examples/MenuFilteringWithSearchInput.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export const MenuFilteringWithSearchInput: React.FunctionComponent = () => {
4949
value={input}
5050
aria-label="Filter menu items"
5151
onChange={(_event, value) => handleTextInputChange(value)}
52+
onClear={() => handleTextInputChange('')}
5253
/>
5354
</MenuSearchInput>
5455
</MenuSearch>

packages/react-core/src/components/Toolbar/examples/ToolbarContentWrap.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
1-
import { Fragment } from 'react';
1+
import { Fragment, useState } from 'react';
22
import { Toolbar, ToolbarItem, ToolbarContent } from '@patternfly/react-core';
33
import { Button, SearchInput } from '@patternfly/react-core';
44

5-
export const ToolbarItems: React.FunctionComponent = () => {
5+
export const ToolbarItems = () => {
6+
const [searchValue, setSearchValue] = useState('');
7+
68
const items = (
79
<Fragment>
810
<ToolbarItem>
9-
<SearchInput aria-label="Items example search input" />
11+
<SearchInput
12+
aria-label="Items example search input"
13+
value={searchValue}
14+
onChange={(_event, value) => setSearchValue(value)}
15+
onClear={() => setSearchValue('')}
16+
/>
1017
</ToolbarItem>
1118
<ToolbarItem>
1219
<Button variant="secondary">Action</Button>

packages/react-core/src/components/Toolbar/examples/ToolbarItems.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,26 @@
1-
import { Fragment } from 'react';
1+
import { Fragment, useState } from 'react';
22
import { Toolbar, ToolbarItem, ToolbarContent } from '@patternfly/react-core';
33
import { Button, SearchInput } from '@patternfly/react-core';
44

5-
export const ToolbarItems: React.FunctionComponent = () => {
5+
export const ToolbarItems = () => {
6+
const [searchValue, setSearchValue] = useState('');
7+
68
const items = (
79
<Fragment>
810
<ToolbarItem>
9-
<SearchInput aria-label="Items example search input" />
11+
<SearchInput
12+
aria-label="Items example search input"
13+
value={searchValue}
14+
onChange={(_event, value) => setSearchValue(value)}
15+
onClear={() => setSearchValue('')}
16+
/>
1017
</ToolbarItem>
1118
<ToolbarItem>
1219
<Button variant="secondary">Action</Button>
1320
</ToolbarItem>
1421
<ToolbarItem variant="separator" />
1522
<ToolbarItem>
16-
<Button variant="primary">Action</Button>
23+
<Button variant="primary">Action2</Button>
1724
</ToolbarItem>
1825
</Fragment>
1926
);

packages/react-core/src/components/Toolbar/examples/ToolbarSticky.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { Fragment, useState } from 'react';
22
import { Toolbar, ToolbarItem, ToolbarContent, SearchInput, Checkbox } from '@patternfly/react-core';
33

4-
export const ToolbarSticky: React.FunctionComponent = () => {
4+
export const ToolbarSticky = () => {
55
const [isSticky, setIsSticky] = useState(true);
66
const [showEvenOnly, setShowEvenOnly] = useState(true);
7+
const [searchValue, setSearchValue] = useState('');
78
const array = Array.from(Array(30), (_, x) => x); // create array of numbers from 1-30 for demo purposes
89
const numbers = showEvenOnly ? array.filter((number) => number % 2 === 0) : array;
910

@@ -13,7 +14,12 @@ export const ToolbarSticky: React.FunctionComponent = () => {
1314
<Toolbar id="toolbar-sticky" inset={{ default: 'insetNone' }} isSticky={isSticky}>
1415
<ToolbarContent>
1516
<ToolbarItem>
16-
<SearchInput aria-label="Sticky example search input" />
17+
<SearchInput
18+
aria-label="Sticky example search input"
19+
value={searchValue}
20+
onChange={(_event, value) => setSearchValue(value)}
21+
onClear={() => setSearchValue('')}
22+
/>
1723
</ToolbarItem>
1824
<ToolbarItem alignSelf="center">
1925
<Checkbox

packages/react-core/src/demos/CustomMenus/examples/InlineSearchFilterMenuDemo.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ export const InlineSearchFilterMenuDemo: React.FunctionComponent = () => {
7878
value={input}
7979
aria-label="Filter menu items"
8080
onChange={(_event, value) => handleTextInputChange(value)}
81+
onClear={(event) => {
82+
event.stopPropagation();
83+
handleTextInputChange('');
84+
}}
8185
/>
8286
</MenuSearchInput>
8387
</MenuSearch>

packages/react-core/src/demos/DataList/examples/DataListExpandableControlInToolbar.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export const DataListExpandableControlInToolbar: React.FunctionComponent = () =>
3838
const [isOpen2, setIsOpen2] = useState(false);
3939
const [isOpen3, setIsOpen3] = useState(false);
4040
const [allExpanded, setAllExpanded] = useState(false);
41+
const [searchValue, setSearchValue] = useState('');
4142

4243
const onToggleAll = () => {
4344
setAllExpanded((prevAllExpanded) => !prevAllExpanded);
@@ -103,7 +104,12 @@ export const DataListExpandableControlInToolbar: React.FunctionComponent = () =>
103104
</Tooltip>
104105
</ToolbarItem>
105106
<ToolbarItem>
106-
<SearchInput aria-label="search input example" />
107+
<SearchInput
108+
aria-label="search input example"
109+
value={searchValue}
110+
onChange={(_event, value) => setSearchValue(value)}
111+
onClear={() => setSearchValue('')}
112+
/>
107113
</ToolbarItem>
108114
<ToolbarItem>
109115
<Button variant="secondary">Action</Button>

packages/react-core/src/demos/examples/Masthead/MastheadWithUtilitiesAndUserDropdownMenu.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ export const MastheadWithUtilitiesAndUserDropdownMenu: React.FunctionComponent =
7474
const [refFullOptions, setRefFullOptions] = useState<Element[]>();
7575
const [favorites, setFavorites] = useState<string[]>([]);
7676
const [filteredIds, setFilteredIds] = useState<string[]>(['*']);
77+
const [searchValue, setSearchValue] = useState('');
7778
const menuRef = useRef<HTMLDivElement>(null);
7879
const toggleRef = useRef<HTMLButtonElement>(null);
7980

@@ -297,6 +298,7 @@ export const MastheadWithUtilitiesAndUserDropdownMenu: React.FunctionComponent =
297298
};
298299

299300
const onTextChange = (textValue: string) => {
301+
setSearchValue(textValue);
300302
if (textValue === '') {
301303
setFilteredIds(['*']);
302304
return;
@@ -331,7 +333,15 @@ export const MastheadWithUtilitiesAndUserDropdownMenu: React.FunctionComponent =
331333
// eslint-disable-next-line no-console
332334
<Menu ref={menuRef} onActionClick={onFavorite} onSelect={(_ev, itemId) => console.log('selected', itemId)}>
333335
<MenuSearchInput>
334-
<SearchInput aria-label="Filter menu items" onChange={(_event, value) => onTextChange(value)} />
336+
<SearchInput
337+
aria-label="Filter menu items"
338+
value={searchValue}
339+
onChange={(_event, value) => onTextChange(value)}
340+
onClear={(event) => {
341+
event.stopPropagation();
342+
onTextChange('');
343+
}}
344+
/>
335345
</MenuSearchInput>
336346
<Divider />
337347
<MenuContent>

packages/react-integration/demo-app-ts/src/components/demos/MenuDemo/MenuDemo.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ export class MenuDemo extends Component {
273273
value={input}
274274
aria-label="filterable-example-with-text-input"
275275
onChange={(_event, value) => this.handleTextInputChange(value, 'input')}
276+
onClear={() => this.handleTextInputChange('', 'input')}
276277
/>
277278
</MenuSearchInput>
278279
</MenuSearch>

0 commit comments

Comments
 (0)