Skip to content

Commit

Permalink
fix: useForwardProps should only forward given props
Browse files Browse the repository at this point in the history
  • Loading branch information
zernonia committed Oct 24, 2023
1 parent 75f59f6 commit a7efff9
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/radix-vue/src/shared/useForwardProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ interface PropOptions {
*/
export function useForwardProps<T extends Record<string, any>>(props: T) {
const vm = getCurrentInstance()

// Default value for declared props
const defaultProps = Object.keys(vm?.type.props ?? {}).reduce((prev, curr) => {
const defaultValue = (vm?.type.props[curr] as PropOptions).default
if (defaultValue !== undefined)
Expand All @@ -32,6 +32,12 @@ export function useForwardProps<T extends Record<string, any>>(props: T) {
Object.keys(assignedProps).forEach((key) => {
preservedProps[camelize(key) as keyof T] = assignedProps[key]
})
return { ...defaultProps, ...preservedProps }

// Only return value from the props parameter
return Object.keys({ ...defaultProps, ...preservedProps }).reduce((prev, curr) => {
if (props[curr])
prev[curr as keyof T] = props[curr]
return prev
}, {} as T)
})
}

0 comments on commit a7efff9

Please sign in to comment.