Skip to content

Commit 0be1594

Browse files
Adjust padding when searchIcon is undefined
1 parent ab81f3d commit 0be1594

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

core/src/components/searchbar/searchbar.ionic.scss

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
--placeholder-color: #{globals.$ion-primitives-neutral-800};
2020
--focus-ring-color: #{globals.$ion-border-focus-default};
2121
--focus-ring-width: #{globals.$ion-border-size-050};
22+
--leading-icon-padding: #{calc(globals.$ion-scale-400 + globals.$ion-space-200)};
2223

2324
@include globals.typography(globals.$ion-body-md-regular);
2425
@include globals.padding(0);
@@ -67,7 +68,7 @@
6768
font-size: globals.$ion-font-size-400;
6869
}
6970

70-
// Searchbar Search & Clear Icon & Cancel Icon
71+
// Searchbar Search Icon & Clear Icon & Cancel Icon
7172
// -----------------------------------------
7273

7374
.searchbar-search-icon,
@@ -80,7 +81,7 @@
8081
transform: translateY(-50%);
8182
}
8283

83-
// Clear Icon & Cancel Icon
84+
// Searchbar Clear Icon & Cancel Icon
8485
// -----------------------------------------
8586

8687
.searchbar-clear-button:focus-visible,
@@ -92,6 +93,12 @@
9293
opacity: 1;
9394
}
9495

96+
// Searchbar Search Icon & Cancel Icon
97+
// -----------------------------------------
98+
:host(:not(.searchbar-has-leading-icons)) {
99+
--leading-icon-padding: #{globals.$ion-scale-0};
100+
}
101+
95102
// Searchbar in Toolbar
96103
// -----------------------------------------
97104

@@ -113,7 +120,7 @@
113120
* the size of the leading icon (search or cancel),
114121
* and the gap between the icon and the input.
115122
*/
116-
padding-inline-start: calc(9px + globals.$ion-scale-400 + globals.$ion-space-200);
123+
padding-inline-start: calc(9px + var(--leading-icon-padding));
117124
}
118125

119126
// Searchbar States
@@ -181,7 +188,7 @@
181188
* the size of the trailing icon (clear),
182189
* and the gap between the icon and the input.
183190
*/
184-
@include globals.padding-horizontal(calc(globals.$ion-space-300 + globals.$ion-scale-400 + globals.$ion-space-200));
191+
@include globals.padding-horizontal(calc(globals.$ion-space-300 + var(--leading-icon-padding)));
185192

186193
height: globals.$ion-scale-1000;
187194
}
@@ -210,7 +217,7 @@
210217
* the size of the trailing icon (clear),
211218
* and the gap between the icon and the input.
212219
*/
213-
@include globals.padding-horizontal(calc(globals.$ion-space-400 + globals.$ion-scale-400 + globals.$ion-space-200));
220+
@include globals.padding-horizontal(calc(globals.$ion-space-400 + var(--leading-icon-padding)));
214221

215222
height: globals.$ion-scale-1200;
216223
}
@@ -229,6 +236,8 @@
229236
/* Large */
230237
:host(.searchbar-size-large) .searchbar-search-icon,
231238
:host(.searchbar-size-large) .searchbar-cancel-button {
239+
--leading-icon-padding: #{calc(globals.$ion-scale-500 + globals.$ion-space-200)};
240+
232241
width: globals.$ion-scale-500;
233242
height: globals.$ion-scale-500;
234243
}
@@ -244,7 +253,7 @@
244253
* the size of the leading icon (search or cancel),
245254
* and the gap between the icon and the input.
246255
*/
247-
padding-inline-start: calc(9px + globals.$ion-scale-500 + globals.$ion-space-200);
256+
padding-inline-start: calc(9px + var(--leading-icon-padding));
248257
}
249258

250259
:host(.searchbar-size-large) .searchbar-input {
@@ -262,7 +271,7 @@
262271
* and the gap between the icon and the input.
263272
*/
264273
@include globals.padding-horizontal(
265-
calc(globals.$ion-space-500 + globals.$ion-scale-500 + globals.$ion-space-200),
274+
calc(globals.$ion-space-500 + var(--leading-icon-padding)),
266275
calc(globals.$ion-space-500 + globals.$ion-scale-400 + globals.$ion-space-200)
267276
);
268277

core/src/components/searchbar/searchbar.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,8 @@ export class Searchbar implements ComponentInterface {
783783
'searchbar-has-value': this.hasValue(),
784784
'searchbar-left-aligned': this.shouldAlignLeft,
785785
'searchbar-has-focus': this.focused,
786+
'searchbar-has-leading-icons':
787+
theme === 'ionic' && (this.searchIcon !== undefined || this.showCancelButton !== 'never'),
786788
'searchbar-should-show-clear': this.shouldShowClearButton(),
787789
'searchbar-should-show-cancel': this.shouldShowCancelButton(),
788790
[`searchbar-shape-${shape}`]: shape !== undefined,
@@ -816,7 +818,14 @@ export class Searchbar implements ComponentInterface {
816818

817819
{(theme === 'md' || theme === 'ionic') && cancelButton}
818820

819-
<ion-icon aria-hidden="true" icon={searchbarSearchIcon} lazy={false} class="searchbar-search-icon"></ion-icon>
821+
{(theme === 'ionic' && this.searchIcon !== undefined) || theme !== 'ionic' ? (
822+
<ion-icon
823+
aria-hidden="true"
824+
icon={searchbarSearchIcon}
825+
lazy={false}
826+
class="searchbar-search-icon"
827+
></ion-icon>
828+
) : null}
820829

821830
<button
822831
aria-label="reset"

0 commit comments

Comments
 (0)