Skip to content

Commit

Permalink
Add Vue emit types (#712)
Browse files Browse the repository at this point in the history
* Add Vue emit types

* ensure value is a boolean

Even though we only use `false` for now

* add Vue emit types for Tabs component

* update changelog

Co-authored-by: henribru <6639509+henribru@users.noreply.github.com>
  • Loading branch information
RobinMalfait and henribru authored Aug 2, 2021
1 parent c111784 commit d60d2a5
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixes

- Only add `type=button` to real buttons ([#709](https://github.com/tailwindlabs/headlessui/pull/709))
- Add Vue emit types ([#679](https://github.com/tailwindlabs/headlessui/pull/679), [#712](https://github.com/tailwindlabs/headlessui/pull/712))

## [@headlessui/react@v1.4.0] - 2021-07-29

Expand Down
2 changes: 1 addition & 1 deletion packages/@headlessui-vue/src/components/dialog/dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export let Dialog = defineComponent({
open: { type: [Boolean, String], default: Missing },
initialFocus: { type: Object as PropType<HTMLElement | null>, default: null },
},
emits: ['close'],
emits: { close: (_close: boolean) => true },
render() {
let propsWeControl = {
// Manually passthrough the attributes, because Vue can't automatically pass
Expand Down
2 changes: 1 addition & 1 deletion packages/@headlessui-vue/src/components/listbox/listbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function useListboxContext(component: string) {

export let Listbox = defineComponent({
name: 'Listbox',
emits: ['update:modelValue'],
emits: { 'update:modelValue': (_value: any) => true },
props: {
as: { type: [Object, String], default: 'template' },
disabled: { type: [Boolean], default: false },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function useRadioGroupContext(component: string) {

export let RadioGroup = defineComponent({
name: 'RadioGroup',
emits: ['update:modelValue'],
emits: { 'update:modelValue': (_value: any) => true },
props: {
as: { type: [Object, String], default: 'div' },
disabled: { type: [Boolean], default: false },
Expand Down
2 changes: 1 addition & 1 deletion packages/@headlessui-vue/src/components/switch/switch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export let SwitchGroup = defineComponent({

export let Switch = defineComponent({
name: 'Switch',
emits: ['update:modelValue'],
emits: { 'update:modelValue': (_value: boolean) => true },
props: {
as: { type: [Object, String], default: 'button' },
modelValue: { type: Boolean, default: false },
Expand Down
4 changes: 3 additions & 1 deletion packages/@headlessui-vue/src/components/tabs/tabs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ function useTabsContext(component: string) {

export let TabGroup = defineComponent({
name: 'TabGroup',
emits: ['change'],
emits: {
change: (_index: number) => true,
},
props: {
as: { type: [Object, String], default: 'template' },
defaultIndex: { type: [Number], default: 0 },
Expand Down
14 changes: 12 additions & 2 deletions packages/@headlessui-vue/src/components/transitions/transition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,12 @@ export let TransitionChild = defineComponent({
leaveFrom: { type: [String], default: '' },
leaveTo: { type: [String], default: '' },
},
emits: ['beforeEnter', 'afterEnter', 'beforeLeave', 'afterLeave'],
emits: {
beforeEnter: () => true,
afterEnter: () => true,
beforeLeave: () => true,
afterLeave: () => true,
},
render() {
if (this.renderAsRoot) {
return h(
Expand Down Expand Up @@ -357,7 +362,12 @@ export let TransitionRoot = defineComponent({
leaveFrom: { type: [String], default: '' },
leaveTo: { type: [String], default: '' },
},
emits: ['beforeEnter', 'afterEnter', 'beforeLeave', 'afterLeave'],
emits: {
beforeEnter: () => true,
afterEnter: () => true,
beforeLeave: () => true,
afterLeave: () => true,
},
render() {
let { show, appear, unmount, ...passThroughProps } = this.$props
let sharedProps = { unmount }
Expand Down

0 comments on commit d60d2a5

Please sign in to comment.