fix(input-stepper): buttons are now toggled for all changes
This commit is contained in:
parent
6589d4cc23
commit
3b388c1d0d
3 changed files with 66 additions and 0 deletions
5
.changeset/afraid-snakes-bake.md
Normal file
5
.changeset/afraid-snakes-bake.md
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'@lion/input-stepper': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fixed the button toggling so it is always toggled if relevant values change
|
||||||
|
|
@ -88,14 +88,20 @@ export class LionInputStepper extends LionInput {
|
||||||
updated(changedProperties) {
|
updated(changedProperties) {
|
||||||
super.updated(changedProperties);
|
super.updated(changedProperties);
|
||||||
|
|
||||||
|
if (changedProperties.has('modelValue')) {
|
||||||
|
this.__toggleSpinnerButtonsState();
|
||||||
|
}
|
||||||
|
|
||||||
if (changedProperties.has('min')) {
|
if (changedProperties.has('min')) {
|
||||||
this._inputNode.min = `${this.min}`;
|
this._inputNode.min = `${this.min}`;
|
||||||
this.values.min = this.min;
|
this.values.min = this.min;
|
||||||
|
this.__toggleSpinnerButtonsState();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (changedProperties.has('max')) {
|
if (changedProperties.has('max')) {
|
||||||
this._inputNode.max = `${this.max}`;
|
this._inputNode.max = `${this.max}`;
|
||||||
this.values.max = this.max;
|
this.values.max = this.max;
|
||||||
|
this.__toggleSpinnerButtonsState();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (changedProperties.has('step')) {
|
if (changedProperties.has('step')) {
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,61 @@ describe('<lion-input-stepper>', () => {
|
||||||
expect(el._inputNode.min).to.equal(el.min.toString());
|
expect(el._inputNode.min).to.equal(el.min.toString());
|
||||||
expect(el._inputNode.max).to.equal(el.max.toString());
|
expect(el._inputNode.max).to.equal(el.max.toString());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should remove the disabled attribute of the decrement button when the min property changes to below the modelvalue', async () => {
|
||||||
|
const el = await fixture(inputStepperWithAttrs);
|
||||||
|
const decrementButton = el.querySelector('[slot=prefix]');
|
||||||
|
el.modelValue = 100;
|
||||||
|
await nextFrame();
|
||||||
|
expect(decrementButton?.getAttribute('disabled')).to.equal('true');
|
||||||
|
el.min = 99;
|
||||||
|
await nextFrame();
|
||||||
|
expect(decrementButton?.getAttribute('disabled')).to.equal(null);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should add the disabled attribute of the decrement button when the min property changes to the modelvalue', async () => {
|
||||||
|
const el = await fixture(inputStepperWithAttrs);
|
||||||
|
const decrementButton = el.querySelector('[slot=prefix]');
|
||||||
|
el.modelValue = 101;
|
||||||
|
await nextFrame();
|
||||||
|
expect(decrementButton?.getAttribute('disabled')).to.equal(null);
|
||||||
|
el.min = 101;
|
||||||
|
await nextFrame();
|
||||||
|
expect(decrementButton?.getAttribute('disabled')).to.equal('true');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should remove the disabled attribute of the increment button when the max property changes to above the modelvalue', async () => {
|
||||||
|
const el = await fixture(inputStepperWithAttrs);
|
||||||
|
const incrementButton = el.querySelector('[slot=suffix]');
|
||||||
|
el.modelValue = 200;
|
||||||
|
await nextFrame();
|
||||||
|
expect(incrementButton?.getAttribute('disabled')).to.equal('true');
|
||||||
|
el.max = 201;
|
||||||
|
await nextFrame();
|
||||||
|
expect(incrementButton?.getAttribute('disabled')).to.equal(null);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should add the disabled attribute of the increment button when the max property changes to the modelvalue', async () => {
|
||||||
|
const el = await fixture(inputStepperWithAttrs);
|
||||||
|
const incrementButton = el.querySelector('[slot=suffix]');
|
||||||
|
el.modelValue = 199;
|
||||||
|
await nextFrame();
|
||||||
|
expect(incrementButton?.getAttribute('disabled')).to.equal(null);
|
||||||
|
el.max = 199;
|
||||||
|
await nextFrame();
|
||||||
|
expect(incrementButton?.getAttribute('disabled')).to.equal('true');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should react to changes in the modelValue by adjusting the disabled state of the button', async () => {
|
||||||
|
const el = await fixture(inputStepperWithAttrs);
|
||||||
|
const incrementButton = el.querySelector('[slot=suffix]');
|
||||||
|
el.modelValue = 199;
|
||||||
|
await nextFrame();
|
||||||
|
expect(incrementButton?.getAttribute('disabled')).to.equal(null);
|
||||||
|
el.modelValue = 200;
|
||||||
|
await nextFrame();
|
||||||
|
expect(incrementButton?.getAttribute('disabled')).to.equal('true');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Accessibility', () => {
|
describe('Accessibility', () => {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue