mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-15 01:03:03 +08:00
fix(angular,vue): range form value updates while dragging knob (#28422)
Issue number: Resolves #28256 --------- <!-- Please do not submit updates to dependencies unless it fixes an issue. --> <!-- Please try to limit your pull request to one type (bugfix, feature, etc). Submit multiple pull requests if needed. --> ## What is the current behavior? <!-- Please describe the current behavior that you are modifying. --> In the form integrations for Angular and Vue, the value of a range does not update while the knob is actively being dragged, only when the knob is released. ## What is the new behavior? <!-- Please describe the behavior or changes that are being added by this PR. --> The form integrations now update the range's value when the `ionInput` event fires, rather than `ionChange`. ## Does this introduce a breaking change? - [ ] Yes - [x] No <!-- If this introduces a breaking change, please describe the impact and migration path for existing applications below. --> ## Other information <!-- Any other information that is important to this PR such as screenshots of how the component looks before and after the change. --> I wasn't sure how to add reliable automated tests for this behavior. The difference only applies when actively dragging the knob, and we've had issues with such gestures being flaky in the past. I did add value displays to the test apps so the behavior can be manually tested.
This commit is contained in:
@ -201,13 +201,13 @@ export const config: Config = {
|
||||
externalEvent: 'ionChange'
|
||||
},
|
||||
{
|
||||
elements: ['ion-datetime', 'ion-radio-group', 'ion-radio', 'ion-range', 'ion-segment', 'ion-segment-button', 'ion-select', 'ion-accordion-group'],
|
||||
elements: ['ion-datetime', 'ion-radio-group', 'ion-radio', 'ion-segment', 'ion-segment-button', 'ion-select', 'ion-accordion-group'],
|
||||
targetAttr: 'value',
|
||||
event: 'v-ion-change',
|
||||
externalEvent: 'ionChange'
|
||||
},
|
||||
{
|
||||
elements: ['ion-input', 'ion-searchbar', 'ion-textarea'],
|
||||
elements: ['ion-input', 'ion-searchbar', 'ion-textarea', 'ion-range'],
|
||||
targetAttr: 'value',
|
||||
event: 'v-ion-input',
|
||||
externalEvent: 'ionInput'
|
||||
|
@ -4,7 +4,7 @@ import { ValueAccessor } from '@ionic/angular/common';
|
||||
|
||||
@Directive({
|
||||
/* tslint:disable-next-line:directive-selector */
|
||||
selector: 'ion-range, ion-select, ion-radio-group, ion-segment, ion-datetime',
|
||||
selector: 'ion-select, ion-radio-group, ion-segment, ion-datetime',
|
||||
providers: [
|
||||
{
|
||||
provide: NG_VALUE_ACCESSOR,
|
||||
@ -20,12 +20,7 @@ export class SelectValueAccessorDirective extends ValueAccessor {
|
||||
|
||||
@HostListener('ionChange', ['$event.target'])
|
||||
_handleChangeEvent(
|
||||
el:
|
||||
| HTMLIonRangeElement
|
||||
| HTMLIonSelectElement
|
||||
| HTMLIonRadioGroupElement
|
||||
| HTMLIonSegmentElement
|
||||
| HTMLIonDatetimeElement
|
||||
el: HTMLIonSelectElement | HTMLIonRadioGroupElement | HTMLIonSegmentElement | HTMLIonDatetimeElement
|
||||
): void {
|
||||
this.handleValueChange(el, el.value);
|
||||
}
|
||||
|
@ -2,8 +2,9 @@ import { ElementRef, Injector, Directive, HostListener } from '@angular/core';
|
||||
import { NG_VALUE_ACCESSOR } from '@angular/forms';
|
||||
import { ValueAccessor } from '@ionic/angular/common';
|
||||
|
||||
// TODO(FW-5495): rename class since range isn't a text component
|
||||
@Directive({
|
||||
selector: 'ion-input:not([type=number]),ion-textarea,ion-searchbar',
|
||||
selector: 'ion-input:not([type=number]),ion-textarea,ion-searchbar,ion-range',
|
||||
providers: [
|
||||
{
|
||||
provide: NG_VALUE_ACCESSOR,
|
||||
@ -18,7 +19,9 @@ export class TextValueAccessorDirective extends ValueAccessor {
|
||||
}
|
||||
|
||||
@HostListener('ionInput', ['$event.target'])
|
||||
_handleInputEvent(el: HTMLIonInputElement | HTMLIonTextareaElement | HTMLIonSearchbarElement): void {
|
||||
_handleInputEvent(
|
||||
el: HTMLIonInputElement | HTMLIonTextareaElement | HTMLIonSearchbarElement | HTMLIonRangeElement
|
||||
): void {
|
||||
this.handleValueChange(el, el.value);
|
||||
}
|
||||
}
|
||||
|
@ -88,8 +88,8 @@ export class IonRange extends ValueAccessor implements OnInit {
|
||||
proxyInputs(IonRange, RANGE_INPUTS);
|
||||
}
|
||||
|
||||
@HostListener('ionChange', ['$event.target'])
|
||||
handleIonChange(el: HTMLIonRangeElement): void {
|
||||
@HostListener('ionInput', ['$event.target'])
|
||||
handleIonInput(el: HTMLIonRangeElement): void {
|
||||
this.handleValueChange(el, el.value);
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@
|
||||
<div slot="label">Range</div>
|
||||
</ion-range>
|
||||
</ion-item>
|
||||
<p>Value: {{ form.controls['range'].value }}</p>
|
||||
</ion-list>
|
||||
<ion-button type="submit">Submit</ion-button>
|
||||
</form>
|
||||
|
@ -630,7 +630,7 @@ export const IonRange = /*@__PURE__*/ defineContainer<JSX.IonRange, JSX.IonRange
|
||||
'ionKnobMoveStart',
|
||||
'ionKnobMoveEnd'
|
||||
],
|
||||
'value', 'v-ion-change', 'ionChange');
|
||||
'value', 'v-ion-input', 'ionInput');
|
||||
|
||||
|
||||
export const IonRefresher = /*@__PURE__*/ defineContainer<JSX.IonRefresher>('ion-refresher', defineIonRefresher, [
|
||||
|
@ -82,6 +82,10 @@ const routes: Array<RouteRecordRaw> = [
|
||||
path: '/components/select',
|
||||
component: () => import('@/views/Select.vue')
|
||||
},
|
||||
{
|
||||
path: '/components/range',
|
||||
component: () => import('@/views/Range.vue')
|
||||
},
|
||||
{
|
||||
path: '/nested',
|
||||
component: () => import('@/views/RouterOutlet.vue'),
|
||||
|
@ -8,6 +8,9 @@
|
||||
<ion-item button router-link="/components/select">
|
||||
<ion-label>Select</ion-label>
|
||||
</ion-item>
|
||||
<ion-item button router-link="/components/range">
|
||||
<ion-label>Range</ion-label>
|
||||
</ion-item>
|
||||
</ion-list>
|
||||
</ion-content>
|
||||
</ion-page>
|
||||
|
53
packages/vue/test/base/src/views/Range.vue
Normal file
53
packages/vue/test/base/src/views/Range.vue
Normal file
@ -0,0 +1,53 @@
|
||||
<template>
|
||||
<ion-page>
|
||||
<ion-header>
|
||||
<ion-toolbar>
|
||||
<ion-title>Range</ion-title>
|
||||
</ion-toolbar>
|
||||
</ion-header>
|
||||
<ion-content>
|
||||
<form>
|
||||
<ion-list>
|
||||
<ion-item>
|
||||
<ion-range :min="0" :max="20" :value="5" v-model="range">
|
||||
<div slot="label">Range</div>
|
||||
</ion-range>
|
||||
</ion-item>
|
||||
<p>Value: {{ range }}</p>
|
||||
</ion-list>
|
||||
</form>
|
||||
</ion-content>
|
||||
</ion-page>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import {
|
||||
IonPage,
|
||||
IonHeader,
|
||||
IonToolbar,
|
||||
IonTitle,
|
||||
IonContent,
|
||||
IonList,
|
||||
IonItem,
|
||||
IonRange
|
||||
} from "@ionic/vue";
|
||||
import { defineComponent } from "vue";
|
||||
|
||||
export default defineComponent({
|
||||
components: {
|
||||
IonPage,
|
||||
IonHeader,
|
||||
IonToolbar,
|
||||
IonTitle,
|
||||
IonContent,
|
||||
IonList,
|
||||
IonItem,
|
||||
IonRange
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
range: 5
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
Reference in New Issue
Block a user