Skip to content

Commit d43c13c

Browse files
committed
test(react): add radio group page
1 parent 9bbb73e commit d43c13c

3 files changed

Lines changed: 93 additions & 0 deletions

File tree

packages/react/test/base/src/App.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ const App: React.FC = () => (
7070
<Route path="/icons" component={Icons} />
7171
<Route path="/inputs" component={Inputs} />
7272
<Route path="/reorder-group" component={ReorderGroup} />
73+
<Route path="/radio-group" component={RadioGroup} />
7374
</IonRouterOutlet>
7475
</IonReactRouter>
7576
</IonApp>

packages/react/test/base/src/pages/Main.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ const Main: React.FC<MainProps> = () => {
5252
<IonItem routerLink="/reorder-group">
5353
<IonLabel>Reorder Group</IonLabel>
5454
</IonItem>
55+
<IonItem routerLink="/radio-group">
56+
<IonLabel>Radio Group</IonLabel>
57+
</IonItem>
5558
</IonList>
5659
</IonContent>
5760
</IonPage>
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import { IonBackButton, IonButtons, IonContent, IonHeader, IonItem, IonList, IonPage, IonRadio, IonRadioGroup, IonSearchbar, IonTitle, IonToolbar } from '@ionic/react';
2+
import React, { useState } from 'react';
3+
4+
interface RadioGroupProps {
5+
6+
}
7+
8+
export interface Item {
9+
text: string;
10+
value: string;
11+
}
12+
13+
const items: Item[] = [
14+
{ text: 'Apple', value: 'apple' },
15+
{ text: 'Apricot', value: 'apricot' },
16+
{ text: 'Banana', value: 'banana' },
17+
{ text: 'Blackberry', value: 'blackberry' },
18+
{ text: 'Blueberry', value: 'blueberry' },
19+
{ text: 'Cherry', value: 'cherry' },
20+
{ text: 'Cranberry', value: 'cranberry' },
21+
{ text: 'Grape', value: 'grape' },
22+
{ text: 'Grapefruit', value: 'grapefruit' },
23+
{ text: 'Guava', value: 'guava' },
24+
];
25+
26+
const RadioGroup: React.FC<RadioGroupProps> = () => {
27+
const [filteredItems, setFilteredItems] = useState<Item[]>([...items]);
28+
29+
const searchbarInput = (event: any) => {
30+
filterList(event.target.value);
31+
};
32+
33+
/**
34+
* Update the rendered view with
35+
* the provided search query. If no
36+
* query is provided, all data
37+
* will be rendered.
38+
*/
39+
const filterList = (searchQuery: string | null | undefined) => {
40+
/**
41+
* If no search query is defined,
42+
* return all options.
43+
*/
44+
if (searchQuery === undefined || searchQuery === null) {
45+
setFilteredItems([...items]);
46+
} else {
47+
/**
48+
* Otherwise, normalize the search
49+
* query and check to see which items
50+
* contain the search query as a substring.
51+
*/
52+
const normalizedQuery = searchQuery.toLowerCase();
53+
setFilteredItems(
54+
items.filter((item) => {
55+
return item.text.toLowerCase().includes(normalizedQuery);
56+
})
57+
);
58+
}
59+
};
60+
61+
return (
62+
<IonPage>
63+
<IonHeader>
64+
<IonToolbar>
65+
<IonButtons slot="start">
66+
<IonBackButton></IonBackButton>
67+
</IonButtons>
68+
<IonTitle>Radio Group</IonTitle>
69+
</IonToolbar>
70+
<IonToolbar>
71+
<IonSearchbar onIonInput={searchbarInput}></IonSearchbar>
72+
</IonToolbar>
73+
</IonHeader>
74+
<IonContent>
75+
<IonList inset={true}>
76+
<IonRadioGroup>
77+
{filteredItems.map((item) => (
78+
<IonItem key={item.value}>
79+
<IonRadio value={item.value}>{item.text}</IonRadio>
80+
</IonItem>
81+
))}
82+
</IonRadioGroup>
83+
</IonList>
84+
</IonContent>
85+
</IonPage>
86+
);
87+
};
88+
89+
export default RadioGroup;

0 commit comments

Comments
 (0)