Skip to content

Commit

Permalink
refactor(noElement): use the full array of VNodes from the default sl…
Browse files Browse the repository at this point in the history
…ot (#1474)
  • Loading branch information
diegopf authored May 22, 2024
1 parent fe08ca2 commit 8fb904c
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 15 deletions.
7 changes: 3 additions & 4 deletions packages/x-components/src/components/global-x-bus.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/
export default defineComponent({
name: 'GlobalXBus',
setup(_, { listeners }) {
setup(_, { listeners, slots }) {
const xBus = useXBus();
/**
Expand All @@ -25,9 +25,8 @@
callback(eventPayload as never, metadata);
});
});
},
render() {
return useNoElementRender(this.$slots);
return () => useNoElementRender(slots);
}
});
</script>
Expand Down
4 changes: 2 additions & 2 deletions packages/x-components/src/components/no-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { useNoElementRender } from '../composables/use-no-element-render';
* @internal
*/
export const NoElement = defineComponent({
render() {
return useNoElementRender(this.$slots);
setup(props, { slots }) {
return () => useNoElementRender(slots);
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ const renderUseNoElementRender = ({
const wrapper = mount(
component ??
(defineComponent({
render() {
return useNoElementRender(this.$slots);
setup(props, { slots }) {
return () => useNoElementRender(slots);
}
}) as ComponentOptions<Vue>),
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ import { VNode } from 'vue/types/vnode';
*/
export function useNoElementRender(
slots: { [key: string]: VNode[] | undefined } | SetupContext['slots']
): VNode {
const defaultSlotContent =
typeof slots.default === 'function' ? slots.default()?.[0] : slots.default?.[0];
): VNode | VNode[] {
const defaultSlotContent = typeof slots.default === 'function' ? slots.default() : slots.default;

return defaultSlotContent ?? h();
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
default: () => []
}
},
setup(props) {
setup(props, { slots }) {
const xBus = useXBus();
/**
Expand Down Expand Up @@ -67,9 +67,8 @@
* computed prop changes.
*/
watch(preselectedFilters, emitPreselectedFilters, { immediate: true });
},
render() {
return useNoElementRender(this.$slots);
return () => useNoElementRender(slots);
}
});
</script>
Expand Down

0 comments on commit 8fb904c

Please sign in to comment.