diff --git a/COMPONENT_INDEX.md b/COMPONENT_INDEX.md index 4728e020..3eda6191 100644 --- a/COMPONENT_INDEX.md +++ b/COMPONENT_INDEX.md @@ -2503,7 +2503,7 @@ None. | currentIndex | let | Yes | number | 0 | Specify the current step index | | vertical | let | No | boolean | false | Set to `true` to use the vertical variant | | spaceEqually | let | No | boolean | false | Set to `true` to specify whether the progress steps should be split equally in size in the div | -| preventChangeOnClick | let | No | boolean | false | Set to `true` to prevent updating `currentIndex` | +| preventChangeOnClick | let | No | boolean | false | Set to `true` to prevent `currentIndex` from updating | ### Slots @@ -2513,13 +2513,13 @@ None. ### Events -| Event name | Type | Detail | -| :--------- | :--------- | :----- | -| click | forwarded | -- | -| mouseover | forwarded | -- | -| mouseenter | forwarded | -- | -| mouseleave | forwarded | -- | -| change | dispatched | -- | +| Event name | Type | Detail | +| :--------- | :--------- | :------------------ | +| change | dispatched | number | +| click | forwarded | -- | +| mouseover | forwarded | -- | +| mouseenter | forwarded | -- | +| mouseleave | forwarded | -- | ## `ProgressIndicatorSkeleton` diff --git a/docs/src/COMPONENT_API.json b/docs/src/COMPONENT_API.json index c5f8abd2..75b47f39 100644 --- a/docs/src/COMPONENT_API.json +++ b/docs/src/COMPONENT_API.json @@ -6697,7 +6697,7 @@ { "name": "preventChangeOnClick", "kind": "let", - "description": "Set to `true` to prevent updating `currentIndex`", + "description": "Set to `true` to prevent `currentIndex` from updating", "type": "boolean", "value": "false", "isFunction": false, @@ -6707,11 +6707,11 @@ ], "slots": [{ "name": "__default__", "default": true, "slot_props": "{}" }], "events": [ + { "type": "dispatched", "name": "change", "detail": "number" }, { "type": "forwarded", "name": "click", "element": "ul" }, { "type": "forwarded", "name": "mouseover", "element": "ul" }, { "type": "forwarded", "name": "mouseenter", "element": "ul" }, - { "type": "forwarded", "name": "mouseleave", "element": "ul" }, - { "type": "dispatched", "name": "change" } + { "type": "forwarded", "name": "mouseleave", "element": "ul" } ], "typedefs": [], "rest_props": { "type": "Element", "name": "ul" } diff --git a/docs/src/pages/framed/ProgressIndicator/ProgrammaticProgressIndicator.svelte b/docs/src/pages/framed/ProgressIndicator/ProgrammaticProgressIndicator.svelte new file mode 100644 index 00000000..6b6c6046 --- /dev/null +++ b/docs/src/pages/framed/ProgressIndicator/ProgrammaticProgressIndicator.svelte @@ -0,0 +1,52 @@ + + + + + + + + + +
+ + +
+ +

Current index: {currentIndex}

diff --git a/src/ProgressIndicator/ProgressIndicator.svelte b/src/ProgressIndicator/ProgressIndicator.svelte index a8e93b77..67d8881f 100644 --- a/src/ProgressIndicator/ProgressIndicator.svelte +++ b/src/ProgressIndicator/ProgressIndicator.svelte @@ -8,7 +8,7 @@ /** Set to `true` to specify whether the progress steps should be split equally in size in the div */ export let spaceEqually = false; - /** Set to `true` to prevent updating `currentIndex` */ + /** Set to `true` to prevent `currentIndex` from updating */ export let preventChangeOnClick = false; import { createEventDispatcher, setContext } from "svelte"; @@ -24,28 +24,40 @@ steps, stepsById, add: (step) => { - steps.update((_) => [ - ..._, - { - ...step, - index: _.length, - current: _.length === currentIndex, - complete: _.length <= currentIndex, - }, - ]); + steps.update((_) => { + if (step.id in $stepsById) { + return _.map((_step) => { + if (_step.id === step.id) return { ..._step, ...step }; + return _step; + }); + } + + return [ + ..._, + { + ...step, + index: _.length, + current: _.length === currentIndex, + complete: step.complete, + }, + ]; + }); }, change: (index) => { if (preventChangeOnClick) return; currentIndex = index; - steps.update((_) => - [..._].map((step, i) => ({ - ...step, - current: i === index, - })) - ); + + /** @event {number} change */ dispatch("change", index); }, }); + + $: steps.update((_) => + _.map((step, i) => ({ + ...step, + current: i === currentIndex, + })) + );