From a5b9066fee1a3cc01fc2aab524bb979fb0096de2 Mon Sep 17 00:00:00 2001 From: KyDenZ Date: Mon, 22 Apr 2019 17:37:58 +0200 Subject: [PATCH] feat(searchbar): add disabled property (#17935) closes #17921 --- angular/src/directives/proxies.ts | 4 ++-- core/api.txt | 1 + core/src/components.d.ts | 8 ++++++++ core/src/components/searchbar/readme.md | 13 +++++++++++++ core/src/components/searchbar/searchbar.scss | 6 ++++++ core/src/components/searchbar/searchbar.tsx | 14 +++++++++++++- .../components/searchbar/test/basic/index.html | 16 ++++++++++++++++ core/src/components/searchbar/usage/angular.md | 3 +++ .../src/components/searchbar/usage/javascript.md | 3 +++ core/src/components/searchbar/usage/react.md | 3 +++ core/src/components/searchbar/usage/vue.md | 3 +++ 11 files changed, 71 insertions(+), 3 deletions(-) diff --git a/angular/src/directives/proxies.ts b/angular/src/directives/proxies.ts index 9acc693024..85140642e2 100644 --- a/angular/src/directives/proxies.ts +++ b/angular/src/directives/proxies.ts @@ -675,7 +675,7 @@ export class IonRow { } export declare interface IonSearchbar extends StencilComponents<'IonSearchbar'> {} -@Component({ selector: 'ion-searchbar', changeDetection: 0, template: '', inputs: ['color', 'mode', 'animated', 'autocomplete', 'autocorrect', 'cancelButtonIcon', 'cancelButtonText', 'clearIcon', 'debounce', 'placeholder', 'searchIcon', 'showCancelButton', 'spellcheck', 'type', 'value'] }) +@Component({ selector: 'ion-searchbar', changeDetection: 0, template: '', inputs: ['color', 'mode', 'animated', 'autocomplete', 'autocorrect', 'cancelButtonIcon', 'cancelButtonText', 'clearIcon', 'debounce', 'disabled', 'placeholder', 'searchIcon', 'showCancelButton', 'spellcheck', 'type', 'value'] }) export class IonSearchbar { ionInput!: EventEmitter; ionChange!: EventEmitter; @@ -691,7 +691,7 @@ export class IonSearchbar { } } proxyMethods(IonSearchbar, ['setFocus', 'getInputElement']); -proxyInputs(IonSearchbar, ['color', 'mode', 'animated', 'autocomplete', 'autocorrect', 'cancelButtonIcon', 'cancelButtonText', 'clearIcon', 'debounce', 'placeholder', 'searchIcon', 'showCancelButton', 'spellcheck', 'type', 'value']); +proxyInputs(IonSearchbar, ['color', 'mode', 'animated', 'autocomplete', 'autocorrect', 'cancelButtonIcon', 'cancelButtonText', 'clearIcon', 'debounce', 'disabled', 'placeholder', 'searchIcon', 'showCancelButton', 'spellcheck', 'type', 'value']); export declare interface IonSegment extends StencilComponents<'IonSegment'> {} @Component({ selector: 'ion-segment', changeDetection: 0, template: '', inputs: ['color', 'mode', 'disabled', 'scrollable', 'value'] }) diff --git a/core/api.txt b/core/api.txt index d56fd0ed5a..f8488ab701 100644 --- a/core/api.txt +++ b/core/api.txt @@ -885,6 +885,7 @@ ion-searchbar,prop,cancelButtonText,string,'Cancel',false,false ion-searchbar,prop,clearIcon,string | undefined,undefined,false,false ion-searchbar,prop,color,string | undefined,undefined,false,false ion-searchbar,prop,debounce,number,250,false,false +ion-searchbar,prop,disabled,boolean,false,false,false ion-searchbar,prop,mode,"ios" | "md",undefined,false,false ion-searchbar,prop,placeholder,string,'Search',false,false ion-searchbar,prop,searchIcon,string,'search',false,false diff --git a/core/src/components.d.ts b/core/src/components.d.ts index e93ea3b137..584f49999d 100644 --- a/core/src/components.d.ts +++ b/core/src/components.d.ts @@ -3720,6 +3720,10 @@ export namespace Components { */ 'debounce': number; /** + * If `true`, the user cannot interact with the input. + */ + 'disabled': boolean; + /** * Returns the native `` element used under the hood. */ 'getInputElement': () => Promise; @@ -3790,6 +3794,10 @@ export namespace Components { */ 'debounce'?: number; /** + * If `true`, the user cannot interact with the input. + */ + 'disabled'?: boolean; + /** * The mode determines which platform styles to use. */ 'mode'?: Mode; diff --git a/core/src/components/searchbar/readme.md b/core/src/components/searchbar/readme.md index 6a9c167ed1..d59a3411aa 100644 --- a/core/src/components/searchbar/readme.md +++ b/core/src/components/searchbar/readme.md @@ -26,6 +26,9 @@ A Searchbar should be used instead of an input to search lists. A clear button i + + + @@ -60,6 +63,9 @@ A Searchbar should be used instead of an input to search lists. A clear button i + + + @@ -100,6 +106,9 @@ const Example: React.SFC<{}> = () => ( {/*-- Searchbar with telephone type --*/} + {/*-- Searchbar disabled --*/} + + {/*-- Searchbar with a cancel button and custom cancel button text --*/} @@ -139,6 +148,9 @@ export default Example; + + + @@ -172,6 +184,7 @@ export default Example; | `clearIcon` | `clear-icon` | Set the clear icon. Defaults to `"close-circle"` for `ios` and `"close"` for `md`. | `string \| undefined` | `undefined` | | `color` | `color` | The color to use from your application's color palette. Default options are: `"primary"`, `"secondary"`, `"tertiary"`, `"success"`, `"warning"`, `"danger"`, `"light"`, `"medium"`, and `"dark"`. For more information on colors, see [theming](/docs/theming/basics). | `string \| undefined` | `undefined` | | `debounce` | `debounce` | Set the amount of time, in milliseconds, to wait to trigger the `ionChange` event after each keystroke. | `number` | `250` | +| `disabled` | `disabled` | If `true`, the user cannot interact with the input. | `boolean` | `false` | | `mode` | `mode` | The mode determines which platform styles to use. | `"ios" \| "md"` | `undefined` | | `placeholder` | `placeholder` | Set the input's placeholder. | `string` | `'Search'` | | `searchIcon` | `search-icon` | The icon to use as the search icon. | `string` | `'search'` | diff --git a/core/src/components/searchbar/searchbar.scss b/core/src/components/searchbar/searchbar.scss index c6ae9ee4d9..d3e029bc4c 100644 --- a/core/src/components/searchbar/searchbar.scss +++ b/core/src/components/searchbar/searchbar.scss @@ -143,3 +143,9 @@ :host(.searchbar-has-value.searchbar-has-focus) .searchbar-clear-button { display: block; } + +:host(.searchbar-disabled) { + cursor: default; + opacity: .4; + pointer-events: none; +} diff --git a/core/src/components/searchbar/searchbar.tsx b/core/src/components/searchbar/searchbar.tsx index 1645a2b2aa..868cafac0a 100644 --- a/core/src/components/searchbar/searchbar.tsx +++ b/core/src/components/searchbar/searchbar.tsx @@ -78,6 +78,11 @@ export class Searchbar implements ComponentInterface { this.ionChange = debounceEvent(this.ionChange, this.debounce); } + /** + * If `true`, the user cannot interact with the input. + */ + @Prop() disabled = false; + /** * Set the input's placeholder. */ @@ -346,16 +351,22 @@ export class Searchbar implements ComponentInterface { return this.value || ''; } + private hasValue(): boolean { + return this.getValue() !== ''; + } + hostData() { const animated = this.animated && this.config.getBoolean('animated', true); return { + 'aria-disabled': this.disabled ? 'true' : null, class: { ...createColorClasses(this.color), [`${this.mode}`]: true, 'searchbar-animated': animated, + 'searchbar-disabled': this.disabled, 'searchbar-no-animate': animated && this.noAnimate, - 'searchbar-has-value': (this.getValue() !== ''), + 'searchbar-has-value': this.hasValue(), 'searchbar-left-aligned': this.shouldAlignLeft, 'searchbar-has-focus': this.focused } @@ -386,6 +397,7 @@ export class Searchbar implements ComponentInterface { return [
this.nativeInput = el} class="searchbar-input" onInput={this.onInput} diff --git a/core/src/components/searchbar/test/basic/index.html b/core/src/components/searchbar/test/basic/index.html index 49cc0501f2..12e54d9be6 100644 --- a/core/src/components/searchbar/test/basic/index.html +++ b/core/src/components/searchbar/test/basic/index.html @@ -29,6 +29,10 @@ +
Search - Disabled
+ + +
Search - Danger
@@ -82,6 +86,10 @@ Toggle Attribute
+
+ Toggle disabled +
+