Skip to content

Commit

Permalink
fix(range): step change
Browse files Browse the repository at this point in the history
  • Loading branch information
aesteves60 authored and dpellier committed Jul 29, 2024
1 parent 851204c commit 79ef842
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ import { type OdsRangeValueChangeEventDetail } from '../../interfaces/event';
tag: 'ods-range',
})
export class OdsRange {
private inputRangeId = 'input-range';
private inputRangeDualId = 'input-range-dual';

private hostId: string = '';
private inputEl?: HTMLInputElement;
private inputElDual?: HTMLInputElement;
private inputObservable?: MutationObserver;
private inputRangeId = 'input-range';
private inputRangeDualId = 'input-range-dual';
private tooltip?: OdsTooltip;
private tooltipDual?: OdsTooltip;

Expand Down Expand Up @@ -106,9 +106,12 @@ export class OdsRange {
setFormValue(this.internals, this.value);
}

@Watch('step')
onStepChange(): void {
this.onInput();
onInputElChange(mutationList: MutationRecord[]): void {
for (const mutation of mutationList) {
if(mutation.attributeName && ['step', 'min', 'max'].includes(mutation.attributeName)) {
this.onInput();
}
}
}

componentWillLoad(): void {
Expand All @@ -121,6 +124,18 @@ export class OdsRange {
this.onValueChange();
}

componentDidLoad(): void {
this.inputObservable = new MutationObserver(this.onInputElChange.bind(this));

if (this.inputEl) {
this.inputObservable.observe(this.inputEl, { attributes: true });
}
}

disconnectedCallback(): void {
this.inputObservable?.disconnect();
}

async formResetCallback(): Promise<void> {
await this.reset();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@ import type { SpecPage } from '@stencil/core/testing';
import { newSpecPage } from '@stencil/core/testing';
import { OdsRange } from '../../src';

const mutationObserverMock = jest.fn(function MutationObserver(callback) {
this.observe = jest.fn();
this.disconnect = jest.fn();
// Optionally add a trigger() method to manually trigger a change
this.trigger = function(mockedMutationsList: MutationRecord[]): void {
callback(mockedMutationsList, this);
};
});
// @ts-ignore mock
global.MutationObserver = mutationObserverMock;

describe('ods-range rendering', () => {
let page: SpecPage;
let root: HTMLElement | undefined;
Expand Down

0 comments on commit 79ef842

Please sign in to comment.