mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-19 03:32:21 +08:00
fix(searchbar): updated searchbar API docs and moved input functions
references #731
This commit is contained in:
@ -11,25 +11,26 @@ import {Button} from '../button/button';
|
|||||||
* @name Searchbar
|
* @name Searchbar
|
||||||
* @module ionic
|
* @module ionic
|
||||||
* @description
|
* @description
|
||||||
* Manages the display of a search bar which can be used to search or filter items.
|
* Manages the display of a Searchbar which can be used to search or filter items.
|
||||||
*
|
*
|
||||||
* @usage
|
* @usage
|
||||||
* ```html
|
* ```html
|
||||||
* <ion-searchbar [(ngModel)]="defaultSearch"></ion-searchbar>
|
* <ion-searchbar [(ngModel)]="defaultSearch"></ion-searchbar>
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* @property [placeholder] - (default: 'Search') Sets input placeholder to value passed in
|
* @property {function} [cancelButtonAction] - the function that gets called by clicking the cancel button
|
||||||
* @property [hideCancelButton] - (default: false) Hides the cancel button
|
* @property {string} [cancelButtonText=Cancel] - sets the cancel button text to the value passed in
|
||||||
* @property [cancelButtonText] - (default: 'Cancel') sets the cancel button text to the value passed in
|
* @property {boolean} [hideCancelButton=false] - Hides the cancel button
|
||||||
* @property [cancelAction] - the function that gets called by clicking the cancel button
|
* @property {string} [placeholder=Search] - Sets input placeholder to the value passed in
|
||||||
|
*
|
||||||
* @see {@link /docs/v2/components#search Search Component Docs}
|
* @see {@link /docs/v2/components#search Search Component Docs}
|
||||||
*/
|
*/
|
||||||
@ConfigComponent({
|
@ConfigComponent({
|
||||||
selector: 'ion-searchbar',
|
selector: 'ion-searchbar',
|
||||||
inputs: [
|
inputs: [
|
||||||
'cancelAction',
|
'cancelButtonAction',
|
||||||
'hideCancelButton',
|
|
||||||
'cancelButtonText',
|
'cancelButtonText',
|
||||||
|
'hideCancelButton',
|
||||||
'placeholder'
|
'placeholder'
|
||||||
],
|
],
|
||||||
outputs: ['input'],
|
outputs: ['input'],
|
||||||
@ -41,7 +42,7 @@ import {Button} from '../button/button';
|
|||||||
'<div class="searchbar-input-container">' +
|
'<div class="searchbar-input-container">' +
|
||||||
'<button (click)="cancelSearchbar($event, query)" clear dark class="searchbar-md-cancel"><icon arrow-back></icon></button>' +
|
'<button (click)="cancelSearchbar($event, query)" clear dark class="searchbar-md-cancel"><icon arrow-back></icon></button>' +
|
||||||
'<div class="searchbar-search-icon"></div>' +
|
'<div class="searchbar-search-icon"></div>' +
|
||||||
'<input [value]="query" class="searchbar-input" type="search" [attr.placeholder]="placeholder">' +
|
'<input [value]="query" (blur)="inputBlurred($event)" (focus)="inputFocused()" class="searchbar-input" type="search" [attr.placeholder]="placeholder">' +
|
||||||
'<button clear *ngIf="query" class="searchbar-clear-icon" (click)="clearInput()"></button>' +
|
'<button clear *ngIf="query" class="searchbar-clear-icon" (click)="clearInput()"></button>' +
|
||||||
'</div>' +
|
'</div>' +
|
||||||
'<button clear (click)="cancelSearchbar($event)" [hidden]="hideCancelButton" class="searchbar-ios-cancel">{{cancelButtonText}}</button>',
|
'<button clear (click)="cancelSearchbar($event)" [hidden]="hideCancelButton" class="searchbar-ios-cancel">{{cancelButtonText}}</button>',
|
||||||
@ -88,7 +89,7 @@ export class Searchbar extends Ion {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* After the view has initialized check if the searchbar has a value
|
* After the view has initialized check if the Searchbar has a value
|
||||||
*/
|
*/
|
||||||
ngAfterViewInit() {
|
ngAfterViewInit() {
|
||||||
this.shouldLeftAlign = this.searchbarInput.value && this.searchbarInput.value.trim() != '';
|
this.shouldLeftAlign = this.searchbarInput.value && this.searchbarInput.value.trim() != '';
|
||||||
@ -96,7 +97,7 @@ export class Searchbar extends Ion {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* Sets the searchbar to focused and aligned left on input focus.
|
* Sets the Searchbar to focused and aligned left on input focus.
|
||||||
*/
|
*/
|
||||||
inputFocused() {
|
inputFocused() {
|
||||||
this.isFocused = true;
|
this.isFocused = true;
|
||||||
@ -105,10 +106,11 @@ export class Searchbar extends Ion {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* Sets the searchbar to not focused and checks if it should align left
|
* Sets the Searchbar to not focused and checks if it should align left
|
||||||
* based on whether there is a value in the searchbar or not on input blur.
|
* based on whether there is a value in the searchbar or not.
|
||||||
*/
|
*/
|
||||||
inputBlurred() {
|
inputBlurred() {
|
||||||
|
console.log("Input Blurred");
|
||||||
this.isFocused = false;
|
this.isFocused = false;
|
||||||
this.shouldLeftAlign = this.searchbarInput.value && this.searchbarInput.value.trim() != '';
|
this.shouldLeftAlign = this.searchbarInput.value && this.searchbarInput.value.trim() != '';
|
||||||
}
|
}
|
||||||
@ -128,11 +130,13 @@ export class Searchbar extends Ion {
|
|||||||
* then calls the custom cancel function if the user passed one in.
|
* then calls the custom cancel function if the user passed one in.
|
||||||
*/
|
*/
|
||||||
cancelSearchbar(event, value) {
|
cancelSearchbar(event, value) {
|
||||||
|
console.log("Clicked Cancel");
|
||||||
this.searchbarInput.elementRef.nativeElement.blur();
|
this.searchbarInput.elementRef.nativeElement.blur();
|
||||||
this.clearInput();
|
this.clearInput();
|
||||||
|
this.isFocused = false;
|
||||||
this.shouldLeftAlign = false;
|
this.shouldLeftAlign = false;
|
||||||
|
|
||||||
this.cancelAction && this.cancelAction(event, value);
|
this.cancelButtonAction && this.cancelButtonAction(event, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -148,8 +152,6 @@ export class Searchbar extends Ion {
|
|||||||
@Directive({
|
@Directive({
|
||||||
selector: '.searchbar-input',
|
selector: '.searchbar-input',
|
||||||
host: {
|
host: {
|
||||||
'(focus)': 'inputFocused()',
|
|
||||||
'(blur)': 'inputBlurred()',
|
|
||||||
'(keyup)': 'inputChanged($event)'
|
'(keyup)': 'inputChanged($event)'
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -201,23 +203,7 @@ export class SearchbarInput {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* Sets the Searchbar input to focused and aligned left on input focus.
|
* Update the Searchbar input value when the input changes
|
||||||
*/
|
|
||||||
inputFocused() {
|
|
||||||
this.searchbar.inputFocused();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @private
|
|
||||||
* Calls the Searchbar function to blur
|
|
||||||
*/
|
|
||||||
inputBlurred() {
|
|
||||||
this.searchbar.inputBlurred();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @private
|
|
||||||
* Update the Searchbar input value
|
|
||||||
*/
|
*/
|
||||||
inputChanged(event) {
|
inputChanged(event) {
|
||||||
this.writeValue(event.target.value);
|
this.writeValue(event.target.value);
|
||||||
|
Reference in New Issue
Block a user