Skip to content

Commit

Permalink
ensure Switch has type="button" (#192)
Browse files Browse the repository at this point in the history
Closes: #178

Co-authored-by: =?UTF-8?q?Oskar=20L=C3=B6fgren?= <[email protected]>

Co-authored-by: =?UTF-8?q?Oskar=20L=C3=B6fgren?= <[email protected]>
  • Loading branch information
RobinMalfait and ulken authored Jan 8, 2021
1 parent e941c70 commit 17a8535
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/@headlessui-react/src/components/switch/switch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ export function Switch<TTag extends React.ElementType = typeof DEFAULT_SWITCH_TA
onKeyPress: handleKeyPress,
}

if (passThroughProps.as === 'button') {
Object.assign(propsWeControl, { type: 'button' })
}

return render({ ...passThroughProps, ...propsWeControl }, propsBag, DEFAULT_SWITCH_TAG)
}

Expand Down
4 changes: 4 additions & 0 deletions packages/@headlessui-vue/src/components/switch/switch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ export const Switch = defineComponent({
onKeyPress: this.handleKeyPress,
}

if (this.$props.as === 'button') {
Object.assign(propsWeControl, { type: 'button' })
}

return render({
props: { ...this.$props, ...propsWeControl },
slot,
Expand Down

0 comments on commit 17a8535

Please sign in to comment.