mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-18 19:21:34 +08:00
fix(all): strong typed events
This commit is contained in:
@ -108,7 +108,7 @@ The value of the segment button.
|
||||
|
||||
## Events
|
||||
|
||||
#### ionClick
|
||||
#### ionSelect
|
||||
|
||||
Emitted when the segment button is clicked.
|
||||
|
||||
|
@ -12,7 +12,6 @@ let ids = 0;
|
||||
}
|
||||
})
|
||||
export class SegmentButton {
|
||||
styleTmr: any;
|
||||
|
||||
@Element() el!: HTMLElement;
|
||||
|
||||
@ -49,31 +48,20 @@ export class SegmentButton {
|
||||
/**
|
||||
* The value of the segment button.
|
||||
*/
|
||||
@Prop({ mutable: true }) value!: string;
|
||||
@Prop() value: string = 'ion-sb-' + (ids++);
|
||||
|
||||
/**
|
||||
* Emitted when the segment button is clicked.
|
||||
*/
|
||||
@Event() ionClick!: EventEmitter;
|
||||
|
||||
componentWillLoad() {
|
||||
if (this.value === undefined) {
|
||||
this.value = `ion-sb-${ids++}`;
|
||||
}
|
||||
}
|
||||
@Event() ionSelect!: EventEmitter<void>;
|
||||
|
||||
/**
|
||||
* Emit the click event to the parent segment
|
||||
*/
|
||||
private segmentButtonClick() {
|
||||
clearTimeout(this.styleTmr);
|
||||
|
||||
this.styleTmr = setTimeout(() => {
|
||||
this.ionClick.emit();
|
||||
});
|
||||
private onClick() {
|
||||
this.ionSelect.emit();
|
||||
}
|
||||
|
||||
|
||||
render() {
|
||||
const themedClasses = createThemedClasses(this.mode, this.color, 'segment-button');
|
||||
const hostClasses = getElementClassMap(this.el.classList);
|
||||
@ -97,7 +85,7 @@ export class SegmentButton {
|
||||
class={buttonClasses}
|
||||
disabled={this.disabled}
|
||||
href={this.href}
|
||||
onClick={this.segmentButtonClick.bind(this)}>
|
||||
onClick={this.onClick.bind(this)}>
|
||||
<slot></slot>
|
||||
{ this.mode === 'md' && <ion-ripple-effect tapClick={true}/> }
|
||||
</TagType>
|
||||
|
@ -2,10 +2,10 @@
|
||||
```html
|
||||
<!-- Segment buttons with text and click listeners -->
|
||||
<ion-segment>
|
||||
<ion-segment-button (ionClick)="segmentButtonClicked($event)">
|
||||
<ion-segment-button (ionSelect)="segmentButtonClicked($event)">
|
||||
Friends
|
||||
</ion-segment-button>
|
||||
<ion-segment-button (ionClick)="segmentButtonClicked($event)">
|
||||
<ion-segment-button (ionSelect)="segmentButtonClicked($event)">
|
||||
Enemies
|
||||
</ion-segment-button>
|
||||
</ion-segment>
|
||||
|
@ -51,7 +51,7 @@
|
||||
// Listen for ionClick on all segment buttons
|
||||
const segmentButtons = document.querySelectorAll('ion-segment-button')
|
||||
for (let i = 0; i < segmentButtons.length; i++) {
|
||||
segmentButtons[i].addEventListener('ionClick', (ev) => {
|
||||
segmentButtons[i].addEventListener('ionSelect', (ev) => {
|
||||
console.log('Segment button clicked', ev);
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user