MCPcopy Create free account
hub / github.com/formkit/formkit / orderSteps

Function orderSteps

packages/addons/src/plugins/multiStep/multiStepPlugin.ts:233–246  ·  view source on GitHub ↗

* Compares steps to DOM order and reorders steps if needed

(node: FormKitNode, steps: FormKitFrameworkContext[])

Source from the content-addressed store, hash-verified

231 * Compares steps to DOM order and reorders steps if needed
232 */
233function orderSteps(node: FormKitNode, steps: FormKitFrameworkContext[]) {
234 if (!isBrowser || !steps) return steps
235 const orderedSteps = [...steps]
236 orderedSteps.sort((a, b) => {
237 const aEl = node.props.__root?.getElementById(a.id)
238 const bEl = node.props.__root?.getElementById(b.id)
239 if (!aEl || !bEl) return 0
240 return aEl.compareDocumentPosition(bEl) === 2 ? 1 : -1
241 })
242 orderedSteps.map((step) => {
243 step.ordered = true
244 })
245 return orderedSteps
246}
247
248/**
249 * Iterates through each step and sets props to help

Callers 1

multiStepPluginFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected