bootstrap-input-spinner 5.0.3 → 5.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bootstrap-input-spinner",
3
- "version": "5.0.3",
3
+ "version": "5.0.4",
4
4
  "description": "A Bootstrap 5 plugin to create input spinner elements for number input.",
5
5
  "browser": "./src/InputSpinner.js",
6
6
  "type": "module",
@@ -272,12 +272,16 @@ export class InputSpinner {
272
272
  }
273
273
 
274
274
  function stepHandling(step) {
275
- calcStep(step)
275
+ // Capture only the direction; re-read self.step on every tick so
276
+ // consumers can change the step attribute mid-hold and have the
277
+ // new value take effect on the next auto-repeat tick.
278
+ const direction = step < 0 ? -1 : 1
279
+ calcStep(direction * self.step)
276
280
  resetTimer()
277
281
  if (self.props.autoInterval !== undefined) {
278
282
  self.autoDelayHandler = setTimeout(function () {
279
283
  self.autoIntervalHandler = setInterval(function () {
280
- calcStep(step)
284
+ calcStep(direction * self.step)
281
285
  }, self.props.autoInterval)
282
286
  }, self.props.autoDelay)
283
287
  }
@@ -187,6 +187,33 @@ describe("InputSpinner stepping", () => {
187
187
  })
188
188
  })
189
189
 
190
+ describe("InputSpinner dynamic step while holding", () => {
191
+ it("picks up a step attribute change on the next auto-repeat tick (regression for #110)", async () => {
192
+ const el = createInput({value: "0", min: "0", max: "1000", step: "1"})
193
+ new InputSpinner(el, {autoDelay: 10, autoInterval: 10})
194
+ const group = el.nextElementSibling
195
+ const btn = group.querySelector(".btn-increment")
196
+
197
+ // Start holding the button: initial step=1 → value becomes 1 synchronously.
198
+ btn.dispatchEvent(new MouseEvent("mousedown", {button: 0, cancelable: true, bubbles: true}))
199
+ assert.equal(el.value, "1")
200
+
201
+ // Swap the step attribute mid-hold. MutationObserver fires the
202
+ // updateAttributes callback, which sets self.step = 10.
203
+ el.setAttribute("step", "10")
204
+ await wait(5)
205
+
206
+ // Wait for a few auto-repeat ticks with the new step.
207
+ await wait(50)
208
+ const mid = parseFloat(el.value)
209
+ assert.true(mid >= 10, "expected value to have advanced by step=10, got " + mid)
210
+
211
+ // Release.
212
+ document.body.dispatchEvent(new MouseEvent("mouseup", {button: 0, bubbles: true}))
213
+ clear()
214
+ })
215
+ })
216
+
190
217
  describe("InputSpinner events", () => {
191
218
  it("dispatches 'input' when stepping", async () => {
192
219
  const {el, group} = spin({value: "5", min: "0", max: "10"})