Skip to content

Commit

Permalink
fix(menu): fix useProviderParent composable childItems type probl…
Browse files Browse the repository at this point in the history
…em (#897)
  • Loading branch information
mlmoravek authored Apr 16, 2024
1 parent 1845b07 commit b9656a6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
5 changes: 3 additions & 2 deletions packages/oruga/src/components/menu/Menu.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { ref, computed, toRaw, type PropType } from "vue";
import { ref, computed, type PropType } from "vue";
import { getOption } from "@/utils/config";
import {
Expand Down Expand Up @@ -95,7 +95,8 @@ const { childItems } = useProviderParent<MenuItemComponent>(rootRef, {
function resetMenu(excludedItems: ProviderItem[] = []): void {
childItems.value.forEach((item) => {
if (!excludedItems.includes(toRaw(item))) item.data.value.reset();
if (!excludedItems.map((i) => i?.identifier).includes(item.identifier))
item.data.reset();
});
}
Expand Down
13 changes: 6 additions & 7 deletions packages/oruga/src/composables/useParentProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
type Component,
type ComputedRef,
type Ref,
type UnwrapNestedRefs,
} from "vue";
import { unrefElement } from "./unrefElement";

Expand Down Expand Up @@ -46,8 +47,8 @@ export function useProviderParent<ItemData = unknown, ParentData = unknown>(
rootRef?: Ref<HTMLElement | Component>,
options?: ProviderParentOptions<ParentData>,
): {
childItems: Ref<ProviderItem<ItemData>[]>;
sortedItems: Ref<ProviderItem<ItemData>[]>;
childItems: Ref<UnwrapNestedRefs<ProviderItem<ItemData>[]>>;
sortedItems: ComputedRef<UnwrapNestedRefs<ProviderItem<ItemData>[]>>;
} {
// getting a hold of the internal instance in setup()
const vm = getCurrentInstance();
Expand All @@ -59,9 +60,7 @@ export function useProviderParent<ItemData = unknown, ParentData = unknown>(
const configField = vm.proxy?.$options.configField;
const key = options?.key ? options.key : configField;

const childItems = ref<ProviderItem<ItemData>[]>([]) as Ref<
ProviderItem<ItemData>[]
>;
const childItems = ref<ProviderItem<ItemData>[]>([]);
const sequence = ref(1);

/**
Expand All @@ -77,15 +76,15 @@ export function useProviderParent<ItemData = unknown, ParentData = unknown>(
const index = childItems.value.length;
const identifier = nextSequence();
const item = { index, data, identifier };
childItems.value.push(item);
childItems.value.push(item as UnwrapNestedRefs<typeof item>);
if (rootRef?.value) {
nextTick(() => {
const ids = childItems.value
.map((item) => `[data-id="${key}-${item.identifier}"]`)
.join(",");
const parent = unrefElement(rootRef);
const children = parent.querySelectorAll(ids);
const sortedIds = Array.from(children).map((el: any) =>
const sortedIds = Array.from(children).map((el) =>
el.getAttribute("data-id").replace(`${key}-`, ""),
);

Expand Down

0 comments on commit b9656a6

Please sign in to comment.