bootstrap-input-spinner 5.0.2 → 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/README.md +12 -13
- package/index.html +1 -0
- package/package.json +2 -2
- package/src/InputSpinner.js +6 -2
- package/test/TestInputSpinner.js +27 -0
package/README.md
CHANGED
|
@@ -17,9 +17,9 @@ A Bootstrap 5 extension to create input spinner elements for number input. Zero
|
|
|
17
17
|
|
|
18
18
|
### Older version, Bootstrap 4 compatible
|
|
19
19
|
|
|
20
|
-
> The current is compatible with **Bootstrap 5
|
|
21
|
-
> <a href="https://github.com/shaack/bootstrap-input-spinner/tree/bootstrap4-compatible">bootstrap4-compatible</a
|
|
22
|
-
> npm package versions 3.x are Bootstrap 5 compatible
|
|
20
|
+
> The current version is compatible with **Bootstrap 5**. A Bootstrap 4 compatible version lives on the
|
|
21
|
+
> <a href="https://github.com/shaack/bootstrap-input-spinner/tree/bootstrap4-compatible">bootstrap4-compatible</a> branch.
|
|
22
|
+
> npm package versions 3.x, 4.x and 5.x are Bootstrap 5 compatible; 2.x is Bootstrap 4 compatible.
|
|
23
23
|
|
|
24
24
|
- [Bootstrap 4 compatible npm package](https://www.npmjs.com/package/bootstrap-input-spinner/v/2.1.2)
|
|
25
25
|
|
|
@@ -31,10 +31,9 @@ The Bootstrap InputSpinner
|
|
|
31
31
|
- automatically changes the value when **holding a button**,
|
|
32
32
|
- has **internationalized** number formatting,
|
|
33
33
|
- allows setting a **prefix** or a **suffix** text in the input,
|
|
34
|
-
- handles **`val()`** like the native element,
|
|
35
34
|
- **dynamically handles** changing **attribute values** like `disabled` or `class`,
|
|
36
|
-
- supports **templates** and **custom editors**,
|
|
37
|
-
- dispatches **`change`** and **`input`** **events on value change** like the native element and
|
|
35
|
+
- supports **templates** and **custom editors**,
|
|
36
|
+
- dispatches **`change`** and **`input`** **events on value change** like the native element, and
|
|
38
37
|
- works **without extra css**, only Bootstrap 5 is needed.
|
|
39
38
|
|
|
40
39
|
## Quickstart
|
|
@@ -51,7 +50,7 @@ npm install bootstrap-input-spinner@2.2.0
|
|
|
51
50
|
```
|
|
52
51
|
|
|
53
52
|
|
|
54
|
-
Or just download the GitHub repository and
|
|
53
|
+
Or just download the GitHub repository and import `src/InputSpinner.js` as an ES module.
|
|
55
54
|
|
|
56
55
|
### HTML
|
|
57
56
|
|
|
@@ -114,7 +113,7 @@ new InputSpinner(element, config)
|
|
|
114
113
|
The default configuration is
|
|
115
114
|
|
|
116
115
|
```javascript
|
|
117
|
-
|
|
116
|
+
const props = {
|
|
118
117
|
decrementButton: "<strong>−</strong>", // button text
|
|
119
118
|
incrementButton: "<strong>+</strong>", // ..
|
|
120
119
|
groupClass: "", // css class of the resulting input-group
|
|
@@ -147,8 +146,8 @@ Additional css class for the `input-group` of the rendered Bootstrap input.
|
|
|
147
146
|
##### buttonsClass
|
|
148
147
|
|
|
149
148
|
The css class of the buttons. Use it to style the increment and decrement buttons as
|
|
150
|
-
described [
|
|
151
|
-
|
|
149
|
+
described [in the Bootstrap 5 button docs](https://getbootstrap.com/docs/5.3/components/buttons/). For example
|
|
150
|
+
`buttonsClass: "btn-primary"` or `"btn-success"`.
|
|
152
151
|
|
|
153
152
|
##### buttonsWidth
|
|
154
153
|
|
|
@@ -196,11 +195,11 @@ new InputSpinner(element, {editor: TimeEditor})
|
|
|
196
195
|
An Editor must implement two functions: `parse(customFormat)` to turn the input string into a number, and
|
|
197
196
|
`render(number)` to format the number back for display.
|
|
198
197
|
|
|
199
|
-
The simplest custom Editor is the `RawEditor`,
|
|
200
|
-
|
|
198
|
+
The simplest custom Editor is the `RawEditor`, which renders and parses the value without any changes, like a native
|
|
199
|
+
number input. It looks like this:
|
|
201
200
|
|
|
202
201
|
```javascript
|
|
203
|
-
|
|
202
|
+
export const RawEditor = function (props, element) {
|
|
204
203
|
this.parse = function (customFormat) {
|
|
205
204
|
// parse nothing
|
|
206
205
|
return customFormat
|
package/index.html
CHANGED
|
@@ -464,6 +464,7 @@ new InputSpinner(document.getElementById("timeEditor"), {editor: TimeEditor})</c
|
|
|
464
464
|
</div>
|
|
465
465
|
<p>If you find bugs or have suggestions, you may write an
|
|
466
466
|
<a href="https://github.com/shaack/bootstrap-input-spinner/issues">issue</a>.</p>
|
|
467
|
+
<p>Run the <a href="./test/">unit tests</a> in your browser.</p>
|
|
467
468
|
<br/><br/>
|
|
468
469
|
</section>
|
|
469
470
|
<script type="module">
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bootstrap-input-spinner",
|
|
3
|
-
"version": "5.0.
|
|
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",
|
|
@@ -31,6 +31,6 @@
|
|
|
31
31
|
"homepage": "https://shaack.com/en/open-source-components",
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"prismjs": "^1.30.0",
|
|
34
|
-
"teevi": "^2.
|
|
34
|
+
"teevi": "^2.4.1"
|
|
35
35
|
}
|
|
36
36
|
}
|
package/src/InputSpinner.js
CHANGED
|
@@ -272,12 +272,16 @@ export class InputSpinner {
|
|
|
272
272
|
}
|
|
273
273
|
|
|
274
274
|
function stepHandling(step) {
|
|
275
|
-
|
|
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
|
}
|
package/test/TestInputSpinner.js
CHANGED
|
@@ -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"})
|