add utils, fix css bug on md

This commit is contained in:
Liam DeBeasi
2019-06-11 12:33:33 -04:00
parent 577318be15
commit bba311653d
3 changed files with 36 additions and 36 deletions

View File

@ -110,7 +110,8 @@
display: block; display: block;
} }
:host(.searchbar-has-focus) .searchbar-cancel-button + .searchbar-search-icon { :host(.searchbar-has-focus) .searchbar-cancel-button + .searchbar-search-icon,
:host(.searchbar-should-show-cancel) .searchbar-cancel-button + .searchbar-search-icon {
display: none; display: none;
} }

View File

@ -5,6 +5,8 @@ import { debounceEvent } from '../../utils/helpers';
import { sanitizeDOMString } from '../../utils/sanitization'; import { sanitizeDOMString } from '../../utils/sanitization';
import { createColorClasses } from '../../utils/theme'; import { createColorClasses } from '../../utils/theme';
import { isCancelButtonSetToFocus, isCancelButtonSetToNever } from './searchbar.utils';
@Component({ @Component({
tag: 'ion-searchbar', tag: 'ion-searchbar',
styleUrls: { styleUrls: {
@ -384,44 +386,13 @@ export class Searchbar implements ComponentInterface {
*/ */
private shouldShowCancelButton(): boolean { private shouldShowCancelButton(): boolean {
if ( if (
this.isCancelButtonSetToNever() || isCancelButtonSetToNever(this.showCancelButton) ||
(this.isCancelButtonSetToFocus() && !this.focused) (isCancelButtonSetToFocus(this.showCancelButton) && !this.focused)
) { return false; } ) { return false; }
return true; return true;
} }
/**
* Wrapper method to check if the cancel button
* should be shown on focus.
*
* TODO: Remove this when the `true` and `false`
* options are removed.
*/
private isCancelButtonSetToFocus(): boolean {
return (
this.showCancelButton === 'focus' ||
this.showCancelButton === 'true' ||
this.showCancelButton === true ||
this.showCancelButton === ''
);
}
/**
* Wrapper method to check if the cancel button
* should never be shown.
*
* TODO: Remove this when the `true` and `false`
* options are removed.
*/
private isCancelButtonSetToNever(): boolean {
return (
this.showCancelButton === 'never' ||
this.showCancelButton === 'false' ||
this.showCancelButton === false
);
}
hostData() { hostData() {
const animated = this.animated && this.config.getBoolean('animated', true); const animated = this.animated && this.config.getBoolean('animated', true);
@ -445,7 +416,7 @@ export class Searchbar implements ComponentInterface {
const clearIcon = this.clearIcon || (this.mode === 'ios' ? 'ios-close-circle' : 'md-close'); const clearIcon = this.clearIcon || (this.mode === 'ios' ? 'ios-close-circle' : 'md-close');
const searchIcon = this.searchIcon; const searchIcon = this.searchIcon;
const cancelButton = !this.isCancelButtonSetToNever() && ( const cancelButton = !isCancelButtonSetToNever(this.showCancelButton) && (
<button <button
type="button" type="button"
tabIndex={this.mode === 'ios' && !this.shouldShowCancelButton() ? -1 : undefined} tabIndex={this.mode === 'ios' && !this.shouldShowCancelButton() ? -1 : undefined}

View File

@ -0,0 +1,28 @@
/**
* Check if the cancel button should never be shown.
*
* TODO: Remove this when the `true` and `false`
* options are removed.
*/
export const isCancelButtonSetToNever = (showCancelButton: boolean | string): boolean => {
return (
showCancelButton === 'never' ||
showCancelButton === 'false' ||
showCancelButton === false
);
};
/**
* Check if the cancel button should be shown on focus.
*
* TODO: Remove this when the `true` and `false`
* options are removed.
*/
export const isCancelButtonSetToFocus = (showCancelButton: boolean | string): boolean => {
return (
showCancelButton === 'focus' ||
showCancelButton === 'true' ||
showCancelButton === true ||
showCancelButton === ''
);
};