MOBILE-3913 core: Add icon option to combobox
parent
91fee7d50b
commit
d9cc05cc37
|
@ -87,6 +87,10 @@ ion-select {
|
||||||
background: var(--background-focused);
|
background: var(--background-focused);
|
||||||
opacity: var(--background-focused-opacity);
|
opacity: var(--background-focused-opacity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&[hidden] {
|
||||||
|
display: none !important;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ion-button {
|
ion-button {
|
||||||
|
|
|
@ -12,10 +12,11 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
import { Component, EventEmitter, Input, Output, ViewEncapsulation } from '@angular/core';
|
import { Component, EventEmitter, Input, Output, ViewChild, ViewEncapsulation } from '@angular/core';
|
||||||
import { Translate } from '@singletons';
|
import { Translate } from '@singletons';
|
||||||
import { ModalOptions } from '@ionic/core';
|
import { ModalOptions } from '@ionic/core';
|
||||||
import { CoreDomUtils } from '@services/utils/dom';
|
import { CoreDomUtils } from '@services/utils/dom';
|
||||||
|
import { IonSelect } from '@ionic/angular';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Component that show a combo select button (combobox).
|
* Component that show a combo select button (combobox).
|
||||||
|
@ -43,6 +44,8 @@ import { CoreDomUtils } from '@services/utils/dom';
|
||||||
})
|
})
|
||||||
export class CoreComboboxComponent {
|
export class CoreComboboxComponent {
|
||||||
|
|
||||||
|
@ViewChild(IonSelect) select!: IonSelect;
|
||||||
|
|
||||||
@Input() interface: 'popover' | 'modal' = 'popover';
|
@Input() interface: 'popover' | 'modal' = 'popover';
|
||||||
@Input() label = Translate.instant('core.show'); // Aria label.
|
@Input() label = Translate.instant('core.show'); // Aria label.
|
||||||
@Input() disabled = false;
|
@Input() disabled = false;
|
||||||
|
@ -51,26 +54,37 @@ export class CoreComboboxComponent {
|
||||||
|
|
||||||
// Additional options when interface modal is selected.
|
// Additional options when interface modal is selected.
|
||||||
@Input() icon?: string; // Icon for modal interface.
|
@Input() icon?: string; // Icon for modal interface.
|
||||||
|
@Input() badge?: number; // Badge number to show near the icon.
|
||||||
@Input() modalOptions?: ModalOptions; // Will emit an event the value changed.
|
@Input() modalOptions?: ModalOptions; // Will emit an event the value changed.
|
||||||
@Input() listboxId = '';
|
@Input() listboxId = '';
|
||||||
|
|
||||||
expanded = false;
|
expanded = false;
|
||||||
|
|
||||||
async showModal(): Promise<void> {
|
/**
|
||||||
if (this.expanded || !this.modalOptions) {
|
* Shows combobox modal.
|
||||||
return;
|
*
|
||||||
}
|
* @param event Event.
|
||||||
this.expanded = true;
|
* @return Promise resolved when done.
|
||||||
|
*/
|
||||||
|
async openSelect(event?: UIEvent): Promise<void> {
|
||||||
|
if (this.interface == 'modal') {
|
||||||
|
if (this.expanded || !this.modalOptions) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.expanded = true;
|
||||||
|
|
||||||
if (this.listboxId) {
|
if (this.listboxId) {
|
||||||
this.modalOptions.id = this.listboxId;
|
this.modalOptions.id = this.listboxId;
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = await CoreDomUtils.openModal(this.modalOptions);
|
const data = await CoreDomUtils.openModal(this.modalOptions);
|
||||||
this.expanded = false;
|
this.expanded = false;
|
||||||
|
|
||||||
if (data) {
|
if (data) {
|
||||||
this.onChange.emit(data);
|
this.onChange.emit(data);
|
||||||
|
}
|
||||||
|
} else if (this.select) {
|
||||||
|
this.select.open(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,27 +1,20 @@
|
||||||
<ion-select
|
<ion-button (click)="openSelect($event)" color="light" *ngIf="interface != 'modal' && icon" [disabled]="disabled">
|
||||||
*ngIf="interface != 'modal'"
|
<ion-icon [name]="icon" [attr.aria-label]="label" slot="start">
|
||||||
class="ion-text-start"
|
</ion-icon>
|
||||||
[(ngModel)]="selection"
|
<ion-badge *ngIf="badge && badge > 0" slot="start">{{badge}}</ion-badge>
|
||||||
(ngModelChange)="onChange.emit(selection)"
|
<div class="select-icon" role="presentation" aria-hidden="true">
|
||||||
[interface]="interface"
|
<div class="select-icon-inner"></div>
|
||||||
[attr.aria-label]="label + ': ' + selection"
|
</div>
|
||||||
[disabled]="disabled"
|
</ion-button>
|
||||||
>
|
<ion-select *ngIf="interface != 'modal'" class="ion-text-start" [(ngModel)]="selection" (ngModelChange)="onChange.emit(selection)"
|
||||||
|
[interface]="interface" [attr.aria-label]="label + ': ' + selection" [disabled]="disabled" [hidden]="!!icon">
|
||||||
<ng-content></ng-content>
|
<ng-content></ng-content>
|
||||||
</ion-select>
|
</ion-select>
|
||||||
|
|
||||||
<ion-button
|
<ion-button *ngIf="interface == 'modal'" aria-haspopup="listbox" [attr.aria-controls]="listboxId" [attr.aria-owns]="listboxId"
|
||||||
*ngIf="interface == 'modal'"
|
[attr.aria-expanded]="expanded" (click)="openSelect()" [disabled]="disabled" expand="block" role="combobox">
|
||||||
aria-haspopup="listbox"
|
|
||||||
aria-controls="addon-mod-forum-sort-order-selector"
|
|
||||||
[attr.aria-owns]="listboxId"
|
|
||||||
[attr.aria-expanded]="expanded"
|
|
||||||
(click)="showModal()"
|
|
||||||
[disabled]="disabled"
|
|
||||||
expand="block"
|
|
||||||
role="combobox"
|
|
||||||
>
|
|
||||||
<ion-icon *ngIf="icon" [name]="icon" slot="start" aria-hidden="true"></ion-icon>
|
<ion-icon *ngIf="icon" [name]="icon" slot="start" aria-hidden="true"></ion-icon>
|
||||||
|
<ion-badge *ngIf="badge && badge > 0" slot="start">{{badge}}</ion-badge>
|
||||||
<span class="sr-only" *ngIf="label">{{ label }}:</span>
|
<span class="sr-only" *ngIf="label">{{ label }}:</span>
|
||||||
<div class="select-text">
|
<div class="select-text">
|
||||||
<slot name="text">{{selection}}</slot>
|
<slot name="text">{{selection}}</slot>
|
||||||
|
|
Loading…
Reference in New Issue