Skip to content

Commit b71f442

Browse files
Adjust padding when the clear button is not present + ellipsis text-overflow
1 parent a97ead6 commit b71f442

File tree

3 files changed

+37
-23
lines changed

3 files changed

+37
-23
lines changed

core/src/components.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3053,7 +3053,7 @@ export namespace Components {
30533053
*/
30543054
"cancelButtonIcon"?: string;
30553055
/**
3056-
* Set the the cancel button text. Only available when the theme is `"ios"`.
3056+
* Set the cancel button text. Only available when the theme is `"ios"`.
30573057
*/
30583058
"cancelButtonText": string;
30593059
/**
@@ -8452,7 +8452,7 @@ declare namespace LocalJSX {
84528452
*/
84538453
"cancelButtonIcon"?: string;
84548454
/**
8455-
* Set the the cancel button text. Only available when the theme is `"ios"`.
8455+
* Set the cancel button text. Only available when the theme is `"ios"`.
84568456
*/
84578457
"cancelButtonText"?: string;
84588458
/**

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
--focus-ring-color: #{globals.$ion-border-focus-default};
2121
--focus-ring-width: #{globals.$ion-border-size-050};
2222
--leading-icon-padding: #{calc(globals.$ion-scale-400 + globals.$ion-space-200)};
23+
--clear-button-padding: #{calc(globals.$ion-scale-400 + globals.$ion-space-200)};
2324

2425
@include globals.typography(globals.$ion-body-md-regular);
2526
@include globals.padding(0);
@@ -40,6 +41,7 @@
4041
@include globals.padding(globals.$ion-space-300, null);
4142

4243
contain: strict;
44+
text-overflow: ellipsis;
4345
}
4446

4547
// Searchbar Clear Input Icon
@@ -56,6 +58,10 @@
5658
contain: strict;
5759
}
5860

61+
:host(:not(.searchbar-should-show-clear)) {
62+
--clear-button-padding: #{globals.$ion-scale-0};
63+
}
64+
5965
// Searchbar Cancel Icon
6066
// -----------------------------------------
6167

@@ -188,7 +194,10 @@
188194
* the size of the trailing icon (clear),
189195
* and the gap between the icon and the input.
190196
*/
191-
@include globals.padding-horizontal(calc(globals.$ion-space-300 + var(--leading-icon-padding)));
197+
@include globals.padding-horizontal(
198+
calc(globals.$ion-space-300 + var(--leading-icon-padding)),
199+
calc(globals.$ion-space-300 + var(--clear-button-padding)),
200+
);
192201

193202
height: globals.$ion-scale-1000;
194203
}
@@ -217,7 +226,10 @@
217226
* the size of the trailing icon (clear),
218227
* and the gap between the icon and the input.
219228
*/
220-
@include globals.padding-horizontal(calc(globals.$ion-space-400 + var(--leading-icon-padding)));
229+
@include globals.padding-horizontal(
230+
calc(globals.$ion-space-400 + var(--leading-icon-padding)),
231+
calc(globals.$ion-space-400 + var(--clear-button-padding))
232+
);
221233

222234
height: globals.$ion-scale-1200;
223235
}
@@ -272,7 +284,7 @@
272284
*/
273285
@include globals.padding-horizontal(
274286
calc(globals.$ion-space-500 + var(--leading-icon-padding)),
275-
calc(globals.$ion-space-500 + globals.$ion-scale-400 + globals.$ion-space-200)
287+
calc(globals.$ion-space-500 + var(--clear-button-padding))
276288
);
277289

278290
height: globals.$ion-scale-1400;

core/src/components/searchbar/searchbar.tsx

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ export class Searchbar implements ComponentInterface {
106106
@Prop() cancelButtonIcon?: string;
107107

108108
/**
109-
* Set the the cancel button text. Only available when the theme is `"ios"`.
109+
* Set the cancel button text. Only available when the theme is `"ios"`.
110110
*/
111111
@Prop() cancelButtonText = 'Cancel';
112112

@@ -827,23 +827,25 @@ export class Searchbar implements ComponentInterface {
827827
></ion-icon>
828828
) : null}
829829

830-
<button
831-
aria-label="reset"
832-
type="button"
833-
no-blur
834-
class="searchbar-clear-button"
835-
onPointerDown={(ev) => {
836-
/**
837-
* This prevents mobile browsers from
838-
* blurring the input when the clear
839-
* button is activated.
840-
*/
841-
ev.preventDefault();
842-
}}
843-
onClick={() => this.onClearInput(true)}
844-
>
845-
<ion-icon aria-hidden="true" icon={searchbarClearIcon} lazy={false} class="searchbar-clear-icon"></ion-icon>
846-
</button>
830+
{theme !== 'ionic' || this.shouldShowClearButton() !== undefined ? (
831+
<button
832+
aria-label="reset"
833+
type="button"
834+
no-blur
835+
class="searchbar-clear-button"
836+
onPointerDown={(ev) => {
837+
/**
838+
* This prevents mobile browsers from
839+
* blurring the input when the clear
840+
* button is activated.
841+
*/
842+
ev.preventDefault();
843+
}}
844+
onClick={() => this.onClearInput(true)}
845+
>
846+
<ion-icon aria-hidden="true" icon={searchbarClearIcon} lazy={false} class="searchbar-clear-icon"></ion-icon>
847+
</button>
848+
) : null}
847849
</div>
848850
{theme === 'ios' && cancelButton}
849851
</Host>

0 commit comments

Comments
 (0)