Skip to content
This repository was archived by the owner on Sep 20, 2024. It is now read-only.

Commit 8e3cdfb

Browse files
refactor(use-disclosure): convert button/disclosure props to computed
1 parent 6e0897d commit 8e3cdfb

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

packages/vue-composables/src/use-disclosure.ts

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -50,39 +50,37 @@ export function useDisclosure(props: UseDisclosureProps = {}) {
5050
const onToggle = () => (isOpen.value ? onClose() : onOpen())
5151

5252
/**
53-
* Ref object containing the HTML attributes for the button that
53+
* Computed object containing the HTML attributes for the button that
5454
* is triggering the disclosure state
5555
*
5656
* `NOTE:` Pass this to the v-bind of the element.
5757
*
5858
* i.e. `v-bind='buttonProps'`
5959
*/
60-
const buttonProps = ref<HTMLAttributes>()
60+
61+
const buttonProps = computed(() => ({
62+
"aria-expanded": isOpen.value,
63+
"aria-controls": id.value,
64+
onClick() {
65+
onToggle()
66+
},
67+
}))
6168

6269
/**
63-
* Ref object containing the HTML attributes for the element that
70+
* Computed object containing the HTML attributes for the element that
6471
* is being effected by the disclosure state.
6572
*
6673
* `NOTE:` Pass this to the v-bind of the element.
6774
*
6875
* i.e. `v-bind='disclosureProps'`
6976
*/
70-
const disclosureProps = ref<HTMLAttributes>()
77+
const disclosureProps = computed(() => ({
78+
hidden: !isOpen.value,
79+
id: id.value,
80+
}))
7181

7282
watchEffect(() => {
7383
isOpen.value = isOpenState.value
74-
buttonProps.value = {
75-
"aria-expanded": isOpen.value,
76-
"aria-controls": id.value,
77-
onClick() {
78-
onToggle()
79-
},
80-
}
81-
82-
disclosureProps.value = {
83-
hidden: !isOpen.value,
84-
id: id.value,
85-
}
8684
})
8785

8886
return {

0 commit comments

Comments
 (0)