-
Notifications
You must be signed in to change notification settings - Fork 462
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(Accordion): emit open
event with index
#1559
Conversation
const { ui, attrs } = useUI('accordion', toRef(props, 'ui'), config, toRef(props, 'class')) | ||
|
||
const uiButton = computed<typeof configButton>(() => configButton) | ||
|
||
const buttonRefs = ref<{ open: boolean, close: (e: EventTarget) => {} }[]>([]) | ||
|
||
const openedStates = computed(() => buttonRefs.value.map(({ open }) => open)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't read directly the button refs in the watcher, because old and new value were identical, I don't know the reason. I had to use this intermediary state to effectively detect the changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you use a function in the watcher? π€
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just passed the refs like this and the values were always equal
watch(buttonRefs, ...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just an idea but what if you use watch(() => buttonRefs.value, ...)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just tried, the exact same thing is happening. I wonder if this is not because the refs are still references to the dom and updated before the watcher's callback is ran, whereas the computed is only updated on the next tick
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That might be the case yes. I don't mind having a computed anyway.
open
event with index
π Linked issue
NA
β Type of change
π Description
This PR introduces a new event for
UAccordion
so that a user can listen to when an accordion item was opened.This could allow the user to lazy load an accordion item's content when opened, for example.
π Checklist