Skip to content

Commit f47153f

Browse files
CR
1 parent 1c3cc35 commit f47153f

File tree

5 files changed

+38
-28
lines changed

5 files changed

+38
-28
lines changed

core/api.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1886,7 +1886,7 @@ ion-searchbar,prop,minlength,number | undefined,undefined,false,false
18861886
ion-searchbar,prop,mode,"ios" | "md",undefined,false,false
18871887
ion-searchbar,prop,name,string,this.inputId,false,false
18881888
ion-searchbar,prop,placeholder,string,'Search',false,false
1889-
ion-searchbar,prop,searchIcon,string | undefined,undefined,false,false
1889+
ion-searchbar,prop,searchIcon,boolean | string | undefined,undefined,false,false
18901890
ion-searchbar,prop,shape,"rectangular" | "round" | "soft" | undefined,undefined,false,false
18911891
ion-searchbar,prop,showCancelButton,"always" | "focus" | "never",'never',false,false
18921892
ion-searchbar,prop,showClearButton,"always" | "focus" | "never",'always',false,false

core/src/components.d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3105,9 +3105,9 @@ export namespace Components {
31053105
*/
31063106
"placeholder": string;
31073107
/**
3108-
* The icon to use as the search icon. Defaults to `"search-outline"` in the `"ios"` theme and `"search-sharp"` in the `"md"` and `"ionic"` themes.
3108+
* The icon to use as the search icon. Defaults to `"search-outline"` in the `"ios"` theme and `"search-sharp"` in the `"md"` and `"ionic"` themes. If `false`, no search icon will be displayed.
31093109
*/
3110-
"searchIcon"?: string;
3110+
"searchIcon"?: string | boolean;
31113111
/**
31123112
* Sets focus on the native `input` in `ion-searchbar`. Use this method instead of the global `input.focus()`. Developers who wish to focus an input when a page enters should call `setFocus()` in the `ionViewDidEnter()` lifecycle method. Developers who wish to focus an input when an overlay is presented should call `setFocus` after `didPresent` has resolved. See [managing focus](/docs/developing/managing-focus) for more information.
31133113
*/
@@ -8528,9 +8528,9 @@ declare namespace LocalJSX {
85288528
*/
85298529
"placeholder"?: string;
85308530
/**
8531-
* The icon to use as the search icon. Defaults to `"search-outline"` in the `"ios"` theme and `"search-sharp"` in the `"md"` and `"ionic"` themes.
8531+
* The icon to use as the search icon. Defaults to `"search-outline"` in the `"ios"` theme and `"search-sharp"` in the `"md"` and `"ionic"` themes. If `false`, no search icon will be displayed.
85328532
*/
8533-
"searchIcon"?: string;
8533+
"searchIcon"?: string | boolean;
85348534
/**
85358535
* Set to `"soft"` for a searchbar with slightly rounded corners, `"round"` for a searchbar with fully rounded corners, or `"rectangular"` for a searchbar without rounded corners. Defaults to `"round"` for the ionic theme, and `undefined` for all other themes.
85368536
*/

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

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
@use "../../themes/ionic/ionic.globals.scss" as globals;
22
@use "searchbar.common";
33

4+
$leading-icon-padding: calc(globals.$ion-scale-400 + globals.$ion-space-200);
5+
$clear-button-padding: calc(globals.$ion-scale-400 + globals.$ion-space-200);
6+
47
// Ionic Searchbar
58
// --------------------------------------------------
69

@@ -15,12 +18,10 @@
1518
--cancel-button-color: #{globals.$ion-primitives-neutral-800};
1619
--clear-button-color: #{globals.$ion-primitives-neutral-1000};
1720
--color: #{globals.$ion-primitives-neutral-1200};
18-
--icon-color: #{globals.$ion-icon-default};
21+
--icon-color: #{globals.$ion-icon-subtlest};
1922
--placeholder-color: #{globals.$ion-text-subtlest};
2023
--focus-ring-color: #{globals.$ion-border-focus-default};
2124
--focus-ring-width: #{globals.$ion-border-size-050};
22-
--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)};
2425

2526
@include globals.typography(globals.$ion-body-md-regular);
2627
@include globals.padding(0);
@@ -60,7 +61,7 @@
6061
}
6162

6263
:host(:not(.searchbar-should-show-clear)) {
63-
--clear-button-padding: #{globals.$ion-scale-0};
64+
$clear-button-padding: #{globals.$ion-scale-0};
6465
}
6566

6667
// Searchbar Cancel Icon
@@ -103,11 +104,11 @@
103104
// Searchbar Search Icon & Cancel Icon
104105
// -----------------------------------------
105106
:host(:not(.searchbar-has-leading-icons)) {
106-
--leading-icon-padding: #{globals.$ion-scale-0};
107+
$leading-icon-padding: #{globals.$ion-scale-0};
107108
}
108109

109-
:host(:not(.searchbar-has-value)) {
110-
--icon-color: #{globals.$ion-icon-subtlest};
110+
:host(.searchbar-has-value) {
111+
--icon-color: #{globals.$ion-icon-default};
111112
}
112113

113114
// Searchbar in Toolbar
@@ -131,7 +132,7 @@
131132
* the size of the leading icon (search or cancel),
132133
* and the gap between the icon and the input.
133134
*/
134-
padding-inline-start: calc(9px + var(--leading-icon-padding));
135+
padding-inline-start: calc(9px + $leading-icon-padding);
135136
}
136137

137138
// Searchbar States
@@ -200,8 +201,8 @@
200201
* and the gap between the icon and the input.
201202
*/
202203
@include globals.padding-horizontal(
203-
calc(globals.$ion-space-300 + var(--leading-icon-padding)),
204-
calc(globals.$ion-space-300 + var(--clear-button-padding))
204+
calc(globals.$ion-space-300 + $leading-icon-padding),
205+
calc(globals.$ion-space-300 + $clear-button-padding)
205206
);
206207

207208
height: globals.$ion-scale-1000;
@@ -231,9 +232,12 @@
231232
* the size of the trailing icon (clear),
232233
* and the gap between the icon and the input.
233234
*/
235+
@debug "Leading icon padding is equal to #{$leading-icon-padding}";
236+
@debug "Clear button padding is equal to #{$clear-button-padding}";
237+
234238
@include globals.padding-horizontal(
235-
calc(globals.$ion-space-400 + var(--leading-icon-padding)),
236-
calc(globals.$ion-space-400 + var(--clear-button-padding))
239+
calc(globals.$ion-space-400 + $leading-icon-padding),
240+
calc(globals.$ion-space-400 + $clear-button-padding)
237241
);
238242

239243
height: globals.$ion-scale-1200;
@@ -253,7 +257,7 @@
253257
/* Large */
254258
:host(.searchbar-size-large) .searchbar-search-icon,
255259
:host(.searchbar-size-large) .searchbar-cancel-button {
256-
--leading-icon-padding: #{calc(globals.$ion-scale-500 + globals.$ion-space-200)};
260+
$leading-icon-padding: #{calc(globals.$ion-scale-500 + globals.$ion-space-200)};
257261

258262
width: globals.$ion-scale-500;
259263
height: globals.$ion-scale-500;
@@ -270,7 +274,7 @@
270274
* the size of the leading icon (search or cancel),
271275
* and the gap between the icon and the input.
272276
*/
273-
padding-inline-start: calc(9px + var(--leading-icon-padding));
277+
padding-inline-start: calc(9px + $leading-icon-padding);
274278
}
275279

276280
:host(.searchbar-size-large) .searchbar-input {
@@ -288,8 +292,8 @@
288292
* and the gap between the icon and the input.
289293
*/
290294
@include globals.padding-horizontal(
291-
calc(globals.$ion-space-500 + var(--leading-icon-padding)),
292-
calc(globals.$ion-space-500 + var(--clear-button-padding))
295+
calc(globals.$ion-space-500 + $leading-icon-padding),
296+
calc(globals.$ion-space-500 + $clear-button-padding)
293297
);
294298

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

core/src/components/searchbar/searchbar.tsx

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,9 @@ export class Searchbar implements ComponentInterface {
179179
/**
180180
* The icon to use as the search icon. Defaults to `"search-outline"` in
181181
* the `"ios"` theme and `"search-sharp"` in the `"md"` and `"ionic"` themes.
182+
* If `false`, no search icon will be displayed.
182183
*/
183-
@Prop() searchIcon?: string;
184+
@Prop() searchIcon?: string | boolean;
184185

185186
/**
186187
* Sets the behavior for the cancel button. Defaults to `"never"`.
@@ -620,13 +621,16 @@ export class Searchbar implements ComponentInterface {
620621
* Clear button should be shown if one of two conditions applies:
621622
* 1. `showClearButton` is set to `always`.
622623
* 2. `showClearButton` is set to `focus`, and the searchbar has been focused.
624+
* 3. `theme` is not set `ionic`, or the searchbar has not been disabled.
623625
*/
624626
private shouldShowClearButton(): boolean {
627+
const theme = getIonTheme(this);
628+
625629
if (this.showClearButton === 'never' || (this.showClearButton === 'focus' && !this.focused)) {
626630
return false;
627631
}
628632

629-
if (getIonTheme(this) === 'ionic' && this.disabled) {
633+
if (theme === 'ionic' && this.disabled) {
630634
return false;
631635
}
632636

@@ -698,7 +702,7 @@ export class Searchbar implements ComponentInterface {
698702
* Otherwise, use the icon set in the config.
699703
* If no icon is set in the config, use the default icon.
700704
*/
701-
get searchbarSearchIcon(): string {
705+
get searchbarSearchIcon(): string | boolean {
702706
// Return the icon if it is explicitly set
703707
if (this.searchIcon != null) {
704708
return this.searchIcon;
@@ -788,7 +792,7 @@ export class Searchbar implements ComponentInterface {
788792
'searchbar-left-aligned': this.shouldAlignLeft,
789793
'searchbar-has-focus': this.focused,
790794
'searchbar-has-leading-icons':
791-
theme === 'ionic' && (this.searchIcon !== undefined || this.showCancelButton !== 'never'),
795+
theme === 'ionic' && (this.searchIcon !== false || this.showCancelButton !== 'never'),
792796
'searchbar-should-show-clear': this.shouldShowClearButton(),
793797
'searchbar-should-show-cancel': this.shouldShowCancelButton(),
794798
[`searchbar-shape-${shape}`]: shape !== undefined,
@@ -822,7 +826,7 @@ export class Searchbar implements ComponentInterface {
822826

823827
{(theme === 'md' || theme === 'ionic') && cancelButton}
824828

825-
{theme !== 'ionic' || this.searchIcon !== undefined ? (
829+
{this.searchIcon !== false ? (
826830
<ion-icon
827831
aria-hidden="true"
828832
icon={searchbarSearchIcon}
@@ -831,7 +835,7 @@ export class Searchbar implements ComponentInterface {
831835
></ion-icon>
832836
) : null}
833837

834-
{theme !== 'ionic' || this.shouldShowClearButton() !== undefined ? (
838+
{this.shouldShowClearButton() ? (
835839
<button
836840
aria-label="reset"
837841
type="button"
@@ -851,7 +855,7 @@ export class Searchbar implements ComponentInterface {
851855
aria-hidden="true"
852856
icon={searchbarClearIcon}
853857
lazy={false}
854-
class="searchbar-clear-icon"
858+
className="searchbar-clear-icon"
855859
></ion-icon>
856860
</button>
857861
) : null}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@ <h5 class="ion-padding-start ion-padding-top">Search - Name</h5>
188188
const propIsSpellcheck = dynamicProp.spellcheck === true ? false : true;
189189
dynamicProp.spellcheck = propIsSpellcheck;
190190
}
191+
192+
document.querySelector("#noCancel").searchIcon = false;
191193
</script>
192194
</ion-content>
193195
</ion-app>

0 commit comments

Comments
 (0)