feat(select): add open method

fixes #14881
This commit is contained in:
Manu Mtz.-Almeida
2018-08-11 17:59:39 +02:00
parent 695abcfbd2
commit 4047812258

View File

@ -1,4 +1,4 @@
import { Component, Element, Event, EventEmitter, Listen, Prop, State, Watch } from '@stencil/core'; import { Component, Element, Event, EventEmitter, Listen, Method, Prop, State, Watch } from '@stencil/core';
import { ActionSheetButton, ActionSheetOptions, AlertInput, AlertOptions, CssClassMap, Mode, PopoverOptions, SelectInputChangeEvent, SelectInterface, SelectPopoverOption, StyleEvent } from '../../interface'; import { ActionSheetButton, ActionSheetOptions, AlertInput, AlertOptions, CssClassMap, Mode, PopoverOptions, SelectInputChangeEvent, SelectInterface, SelectPopoverOption, StyleEvent } from '../../interface';
import { deferEvent, renderHiddenInput } from '../../utils/helpers'; import { deferEvent, renderHiddenInput } from '../../utils/helpers';
@ -256,15 +256,8 @@ export class Select {
this.emitStyle(); this.emitStyle();
} }
private getLabel() { @Method()
const item = this.el.closest('ion-item'); open(ev?: UIEvent) {
if (item) {
return item.querySelector('ion-label');
}
return null;
}
private open(ev: UIEvent) {
let selectInterface = this.interface; let selectInterface = this.interface;
if ((selectInterface === 'action-sheet' || selectInterface === 'popover') && this.multiple) { if ((selectInterface === 'action-sheet' || selectInterface === 'popover') && this.multiple) {
@ -278,7 +271,7 @@ export class Select {
} }
if (selectInterface === 'popover') { if (selectInterface === 'popover') {
return this.openPopover(ev); return this.openPopover(ev!);
} }
if (selectInterface === 'action-sheet') { if (selectInterface === 'action-sheet') {
@ -288,6 +281,14 @@ export class Select {
return this.openAlert(); return this.openAlert();
} }
private getLabel() {
const item = this.el.closest('ion-item');
if (item) {
return item.querySelector('ion-label');
}
return null;
}
private async openPopover(ev: UIEvent) { private async openPopover(ev: UIEvent) {
const interfaceOptions = this.interfaceOptions; const interfaceOptions = this.interfaceOptions;
@ -295,6 +296,8 @@ export class Select {
...interfaceOptions, ...interfaceOptions,
component: 'ion-select-popover', component: 'ion-select-popover',
cssClass: ['select-popover', interfaceOptions.cssClass],
event: ev,
componentProps: { componentProps: {
header: interfaceOptions.header, header: interfaceOptions.header,
subHeader: interfaceOptions.subHeader, subHeader: interfaceOptions.subHeader,
@ -312,9 +315,7 @@ export class Select {
} }
} as SelectPopoverOption; } as SelectPopoverOption;
}) })
}, }
cssClass: ['select-popover', interfaceOptions.cssClass],
ev
}; };
const popover = this.overlay = await this.popoverCtrl.create(popoverOpts); const popover = this.overlay = await this.popoverCtrl.create(popoverOpts);