Skip to content

Commit 24c1f6e

Browse files
committed
fix: fixed useDivideAttrs not correctly dividing attributes
1 parent 14da66d commit 24c1f6e

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/composables/useDivideAttrs.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,21 @@ import { computed, type Ref, useAttrs } from "vue"
2929
export const useDivideAttrs = <T extends readonly string[]>(divisionKeys: T): Ref<Record<`${T[number]}Attrs` | "attrs", Record<string, any>>> => computed(() => {
3030
const attrs: Record<string, any> = useAttrs()
3131
const res: any = { attrs: {} }
32+
const unseen = keys(attrs)
3233
for (const key of divisionKeys) {
3334
res[`${key}Attrs`] = {}
34-
for (const attrKey of keys(attrs)) {
35+
for (const attrKey of unseen) {
3536
if (attrKey.startsWith(`${key}-`)) {
3637
res[`${key}Attrs`][attrKey.slice(key.length + 1)] = attrs[attrKey]
38+
unseen.splice(unseen.indexOf(attrKey), 1)
3739
} else if (attrKey.startsWith(key)) {
3840
res[`${key}Attrs`][attrKey.slice(key.length)] = attrs[attrKey]
39-
} else {
40-
res.attrs[attrKey] = attrs[attrKey]
41+
unseen.splice(unseen.indexOf(attrKey), 1)
4142
}
4243
}
4344
}
45+
for (const attrKey of unseen) {
46+
res.attrs[attrKey] = attrs[attrKey]
47+
}
4448
return res
4549
})

0 commit comments

Comments
 (0)