mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-19 19:57:22 +08:00
fix(inputs): disabled handling (#16071)
This commit is contained in:
@ -2,7 +2,7 @@ import { Component, ComponentInterface, Element, Event, EventEmitter, Prop, Queu
|
||||
|
||||
import { CheckedInputChangeEvent, Color, Gesture, GestureDetail, Mode, StyleEvent } from '../../interface';
|
||||
import { hapticSelection } from '../../utils/haptic';
|
||||
import { deferEvent, renderHiddenInput } from '../../utils/helpers';
|
||||
import { renderHiddenInput } from '../../utils/helpers';
|
||||
import { createColorClasses, hostContext } from '../../utils/theme';
|
||||
|
||||
@Component({
|
||||
@ -51,14 +51,14 @@ export class Toggle implements ComponentInterface {
|
||||
@Prop({ mutable: true }) checked = false;
|
||||
|
||||
/**
|
||||
* If `true`, the user cannot interact with the toggle. Default false.
|
||||
* If `true`, the user cannot interact with the toggle. Defaults to `false`.
|
||||
*/
|
||||
@Prop() disabled = false;
|
||||
|
||||
/**
|
||||
* the value of the toggle.
|
||||
*/
|
||||
@Prop() value = 'on';
|
||||
@Prop() value?: string | null = 'on';
|
||||
|
||||
/**
|
||||
* Emitted when the value property has changed.
|
||||
@ -90,16 +90,14 @@ export class Toggle implements ComponentInterface {
|
||||
|
||||
@Watch('disabled')
|
||||
disabledChanged() {
|
||||
this.ionStyle.emit({
|
||||
'interactive-disabled': this.disabled,
|
||||
});
|
||||
this.emitStyle();
|
||||
if (this.gesture) {
|
||||
this.gesture.setDisabled(this.disabled);
|
||||
}
|
||||
}
|
||||
|
||||
componentWillLoad() {
|
||||
this.ionStyle = deferEvent(this.ionStyle);
|
||||
this.emitStyle();
|
||||
}
|
||||
|
||||
async componentDidLoad() {
|
||||
@ -125,6 +123,12 @@ export class Toggle implements ComponentInterface {
|
||||
this.disabledChanged();
|
||||
}
|
||||
|
||||
private emitStyle() {
|
||||
this.ionStyle.emit({
|
||||
'interactive-disabled': this.disabled,
|
||||
});
|
||||
}
|
||||
|
||||
private onStart(detail: GestureDetail) {
|
||||
this.pivotX = detail.currentX;
|
||||
this.activated = true;
|
||||
@ -171,6 +175,10 @@ export class Toggle implements ComponentInterface {
|
||||
this.ionBlur.emit();
|
||||
}
|
||||
|
||||
private getValue() {
|
||||
return this.value || '';
|
||||
}
|
||||
|
||||
hostData() {
|
||||
return {
|
||||
class: {
|
||||
@ -186,7 +194,8 @@ export class Toggle implements ComponentInterface {
|
||||
}
|
||||
|
||||
render() {
|
||||
renderHiddenInput(this.el, this.name, (this.checked ? this.value : ''), this.disabled);
|
||||
const value = this.getValue();
|
||||
renderHiddenInput(this.el, this.name, (this.checked ? value : ''), this.disabled);
|
||||
|
||||
return [
|
||||
<div class="toggle-icon">
|
||||
@ -201,7 +210,7 @@ export class Toggle implements ComponentInterface {
|
||||
checked={this.checked}
|
||||
id={this.inputId}
|
||||
name={this.name}
|
||||
value={this.value}
|
||||
value={value}
|
||||
disabled={this.disabled}
|
||||
ref={r => this.nativeInput = (r as any)}
|
||||
/>,
|
||||
|
Reference in New Issue
Block a user