Skip to content

Commit ab61c12

Browse files
refactor(searchbar): update default styles for ionic theme (#29917)
Co-authored-by: Brandy Carney <[email protected]>
1 parent c295a08 commit ab61c12

File tree

43 files changed

+210
-47
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+210
-47
lines changed

core/api.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1915,6 +1915,8 @@ ion-searchbar,css-prop,--clear-button-color,md
19151915
ion-searchbar,css-prop,--color,ionic
19161916
ion-searchbar,css-prop,--color,ios
19171917
ion-searchbar,css-prop,--color,md
1918+
ion-searchbar,css-prop,--focus-ring-color,ionic
1919+
ion-searchbar,css-prop,--focus-ring-width,ionic
19181920
ion-searchbar,css-prop,--icon-color,ionic
19191921
ion-searchbar,css-prop,--icon-color,ios
19201922
ion-searchbar,css-prop,--icon-color,md
Lines changed: 112 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,63 @@
1-
@use "searchbar.common";
21
@use "../../themes/ionic/ionic.globals.scss" as globals;
2+
@use "searchbar.common";
33

44
// Ionic Searchbar
55
// --------------------------------------------------
66

77
:host {
8+
/**
9+
* @prop --focus-ring-color: The color of the ring around the focused element.
10+
* @prop --focus-ring-width: The width of the ring around the focused element.
11+
*/
812
--background: #{globals.$ionic-color-neutral-100};
9-
--border-radius: #{globals.$ionic-border-radius-800};
13+
--border-radius: #{globals.$ionic-border-radius-400};
1014
--box-shadow: none;
1115
--cancel-button-color: #{globals.$ionic-color-neutral-800};
12-
--clear-button-color: #{globals.$ionic-color-neutral-800};
13-
--color: #{globals.$ionic-color-neutral-800};
16+
--clear-button-color: #{globals.$ionic-color-neutral-1000};
17+
--color: #{globals.$ionic-color-neutral-1200};
1418
--icon-color: #{globals.$ionic-color-neutral-800};
19+
--placeholder-color: #{globals.$ionic-color-neutral-800};
20+
--focus-ring-color: #{globals.$ionic-state-focus-1};
21+
--focus-ring-width: #{globals.$ionic-border-size-050};
1522

23+
@include globals.typography(globals.$ionic-body-md-regular);
1624
@include globals.padding(0);
17-
18-
min-height: globals.$ionic-scale-1000;
19-
20-
contain: content;
21-
}
22-
23-
.searchbar-input-container {
24-
min-height: globals.$ionic-scale-1000;
2525
}
2626

2727
// Searchbar Search Icon
2828
// -----------------------------------------
2929

3030
.searchbar-search-icon {
31-
display: none;
31+
// Position is based on the size of the search icon.
32+
@include globals.position(globals.$ionic-scale-400, null, null, globals.$ionic-scale-400);
33+
34+
width: globals.$ionic-scale-400;
35+
height: globals.$ionic-scale-400;
3236
}
3337

3438
// Searchbar Input Field
3539
// -----------------------------------------
3640

3741
.searchbar-input {
38-
@include globals.padding(globals.$ionic-space-300);
39-
40-
height: 100%;
41-
42-
font-size: globals.$ionic-font-size-350;
43-
font-weight: globals.$ionic-font-weight-regular;
42+
/**
43+
* Padding start is based on
44+
* desired padding from design,
45+
* the size of the search icon,
46+
* and the gap between the icon and the input.
47+
*
48+
* Padding end is based on
49+
* desired padding from design,
50+
* the size of the clear icon,
51+
* and the gap between the icon and the input.
52+
*/
53+
@include globals.padding(
54+
globals.$ionic-space-300,
55+
calc(globals.$ionic-space-400 + globals.$ionic-scale-400 + globals.$ionic-space-200),
56+
globals.$ionic-space-300,
57+
calc(globals.$ionic-space-400 + globals.$ionic-scale-400 + globals.$ionic-space-200)
58+
);
59+
60+
min-height: globals.$ionic-scale-1200;
4461

4562
contain: strict;
4663
}
@@ -49,25 +66,94 @@
4966
// -----------------------------------------
5067

5168
.searchbar-clear-button {
52-
@include globals.position(50%, globals.$ionic-space-200, null, null);
69+
// Position is based on the size of the clear icon.
70+
@include globals.position(globals.$ionic-scale-400, globals.$ionic-scale-400, null, null);
5371

54-
position: absolute;
72+
width: globals.$ionic-scale-400;
73+
height: globals.$ionic-scale-400;
5574

56-
width: globals.$ionic-scale-600;
57-
height: globals.$ionic-scale-600;
75+
background-color: transparent;
76+
77+
font-size: globals.$ionic-scale-400;
78+
79+
contain: strict;
80+
}
5881

59-
transform: translateY(-50%);
82+
// Searchbar Cancel Icon
83+
// -----------------------------------------
84+
85+
.searchbar-cancel-button {
86+
/**
87+
* The left edge of the cancel button
88+
* should align with the left edge
89+
* of the back button if the searchbar
90+
* is used in a toolbar.
91+
*/
92+
@include globals.position(0, null, null, 9px);
6093

6194
background-color: transparent;
6295

6396
font-size: globals.$ionic-font-size-400;
97+
}
6498

65-
contain: strict;
99+
// Searchbar Search & Clear Icon & Cancel Icon
100+
// -----------------------------------------
101+
102+
.searchbar-search-icon,
103+
.searchbar-clear-button,
104+
.searchbar-cancel-button {
105+
position: absolute;
106+
}
107+
108+
// Clear Icon & Cancel Icon
109+
// -----------------------------------------
110+
111+
.searchbar-clear-button:focus-visible,
112+
.searchbar-cancel-button:focus-visible ion-icon {
113+
@include globals.border-radius(globals.$ionic-border-radius-100);
114+
115+
outline: globals.$ionic-border-size-050 globals.$ionic-border-style-solid globals.$ionic-state-focus-1;
116+
117+
opacity: 1;
66118
}
67119

68120
// Searchbar in Toolbar
69121
// -----------------------------------------
70122

71123
:host-context(ion-toolbar) {
72-
min-height: globals.$ionic-scale-1000;
124+
min-height: globals.$ionic-scale-1200;
125+
}
126+
127+
// Searchbar States
128+
// --------------------------------------------------
129+
130+
/* Hover */
131+
:host(:hover) {
132+
--background: #{globals.$ionic-color-neutral-200};
133+
}
134+
135+
/* Focus */
136+
:host(.searchbar-has-focus) .searchbar-input {
137+
outline: var(--focus-ring-width) globals.$ionic-border-style-solid var(--focus-ring-color);
138+
}
139+
140+
:host(.searchbar-has-focus) .searchbar-search-icon,
141+
:host(.searchbar-has-focus) .searchbar-cancel-button,
142+
:host(.searchbar-should-show-cancel) .searchbar-cancel-button {
143+
display: block;
144+
}
145+
146+
:host(.searchbar-has-focus) .searchbar-cancel-button + .searchbar-search-icon,
147+
:host(.searchbar-should-show-cancel) .searchbar-cancel-button + .searchbar-search-icon {
148+
display: none;
149+
}
150+
151+
/* Disabled */
152+
:host(.searchbar-disabled) {
153+
--color: #{globals.$ionic-color-neutral-500};
154+
--icon-color: #{globals.$ionic-color-neutral-500};
155+
--placeholder-color: #{globals.$ionic-color-neutral-500};
156+
157+
cursor: default;
158+
pointer-events: none;
73159
}

core/src/components/searchbar/test/basic/index.html

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,18 @@
1212
<script src="../../../../../scripts/testing/scripts.js"></script>
1313
<script nomodule src="../../../../../dist/ionic/ionic.js"></script>
1414
<script type="module" src="../../../../../dist/ionic/ionic.esm.js"></script>
15+
16+
<style>
17+
/* TODO(ROU-11256): Remove the border that is added through the testing styling */
18+
ion-searchbar button {
19+
border: none;
20+
padding: initial;
21+
}
22+
</style>
1523
</head>
1624

1725
<body>
1826
<ion-app>
19-
<ion-header>
20-
<ion-toolbar>
21-
<ion-title>Searchbar - Basic</ion-title>
22-
</ion-toolbar>
23-
</ion-header>
24-
2527
<ion-content id="content">
2628
<h5 class="ion-padding-start ion-padding-top">Search - Default</h5>
2729
<ion-searchbar id="basic" value="test" type="tel" show-cancel-button="focus" debounce="500"> </ion-searchbar>

core/src/components/searchbar/test/basic/searchbar.e2e.ts

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ configs({ modes: ['ios'], directions: ['ltr'] }).forEach(({ title, config }) =>
9595
});
9696
});
9797

98-
configs().forEach(({ title, screenshot, config }) => {
98+
configs({ modes: ['md', 'ios', 'ionic-md'] }).forEach(({ title, screenshot, config }) => {
9999
test.describe(title('searchbar: rendering'), () => {
100100
test('should render searchbar', async ({ page }) => {
101101
await page.setContent(
@@ -143,19 +143,6 @@ configs({ directions: ['ltr'] }).forEach(({ title, screenshot, config }) => {
143143
await expect(searchbar).toHaveScreenshot(screenshot(`searchbar-color`));
144144
});
145145

146-
test('should render disabled searchbar', async ({ page }) => {
147-
await page.setContent(
148-
`
149-
<ion-searchbar disabled="true"></ion-searchbar>
150-
`,
151-
config
152-
);
153-
154-
const searchbar = page.locator('ion-searchbar');
155-
156-
await expect(searchbar).toHaveScreenshot(screenshot(`searchbar-disabled`));
157-
});
158-
159146
test('should render custom search icon', async ({ page }) => {
160147
await page.setContent(
161148
`
@@ -199,7 +186,7 @@ configs({ modes: ['ios'], directions: ['ltr'] }).forEach(({ title, screenshot, c
199186
});
200187
});
201188

202-
configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, screenshot, config }) => {
189+
configs({ modes: ['md', 'ionic-md'], directions: ['ltr'] }).forEach(({ title, screenshot, config }) => {
203190
test.describe(title('searchbar: cancel button alignment'), () => {
204191
test('should align with the back button when used in a toolbar', async ({ page }, testInfo) => {
205192
testInfo.annotations.push({

0 commit comments

Comments
 (0)