diff --git a/src/core/components/combobox/combobox.scss b/src/core/components/combobox/combobox.scss index 501321352..110a97d5f 100644 --- a/src/core/components/combobox/combobox.scss +++ b/src/core/components/combobox/combobox.scss @@ -87,6 +87,10 @@ ion-select { background: var(--background-focused); opacity: var(--background-focused-opacity); } + + &[hidden] { + display: none !important; + } } ion-button { diff --git a/src/core/components/combobox/combobox.ts b/src/core/components/combobox/combobox.ts index 617e6801d..c66579939 100644 --- a/src/core/components/combobox/combobox.ts +++ b/src/core/components/combobox/combobox.ts @@ -12,10 +12,11 @@ // See the License for the specific language governing permissions and // 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 { ModalOptions } from '@ionic/core'; import { CoreDomUtils } from '@services/utils/dom'; +import { IonSelect } from '@ionic/angular'; /** * Component that show a combo select button (combobox). @@ -43,6 +44,8 @@ import { CoreDomUtils } from '@services/utils/dom'; }) export class CoreComboboxComponent { + @ViewChild(IonSelect) select!: IonSelect; + @Input() interface: 'popover' | 'modal' = 'popover'; @Input() label = Translate.instant('core.show'); // Aria label. @Input() disabled = false; @@ -51,26 +54,37 @@ export class CoreComboboxComponent { // Additional options when interface modal is selected. @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() listboxId = ''; expanded = false; - async showModal(): Promise { - if (this.expanded || !this.modalOptions) { - return; - } - this.expanded = true; + /** + * Shows combobox modal. + * + * @param event Event. + * @return Promise resolved when done. + */ + async openSelect(event?: UIEvent): Promise { + if (this.interface == 'modal') { + if (this.expanded || !this.modalOptions) { + return; + } + this.expanded = true; - if (this.listboxId) { - this.modalOptions.id = this.listboxId; - } + if (this.listboxId) { + this.modalOptions.id = this.listboxId; + } - const data = await CoreDomUtils.openModal(this.modalOptions); - this.expanded = false; + const data = await CoreDomUtils.openModal(this.modalOptions); + this.expanded = false; - if (data) { - this.onChange.emit(data); + if (data) { + this.onChange.emit(data); + } + } else if (this.select) { + this.select.open(event); } } diff --git a/src/core/components/combobox/core-combobox.html b/src/core/components/combobox/core-combobox.html index aad62d2af..6b3d2ceb2 100644 --- a/src/core/components/combobox/core-combobox.html +++ b/src/core/components/combobox/core-combobox.html @@ -1,27 +1,20 @@ - + + + + {{badge}} + + + - + + {{badge}} {{ label }}:
{{selection}}