-
Notifications
You must be signed in to change notification settings - Fork 465
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(Table): emit expand
event
#2063
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -83,7 +83,7 @@ | |
<UButton | ||
v-bind="{ ...(ui.default.expandButton || {}), ...expandButton }" | ||
:ui="{ icon: { base: [ui.expand.icon, openedRows.includes(index) && 'rotate-180'] } }" | ||
@click="toggleOpened(index)" | ||
@click="toggleOpened({ index, row })" | ||
/> | ||
</td> | ||
|
||
|
@@ -154,6 +154,10 @@ interface Column { | |
[key: string]: any | ||
} | ||
|
||
interface Row { | ||
[key: string]: any | ||
} | ||
|
||
export default defineComponent({ | ||
components: { | ||
UIcon, | ||
|
@@ -172,7 +176,7 @@ export default defineComponent({ | |
default: () => defaultComparator | ||
}, | ||
rows: { | ||
type: Array as PropType<{ [key: string]: any }[]>, | ||
type: Array as PropType<Row[]>, | ||
default: () => [] | ||
}, | ||
columns: { | ||
|
@@ -236,7 +240,7 @@ export default defineComponent({ | |
default: () => ({}) | ||
} | ||
}, | ||
emits: ['update:modelValue', 'update:sort'], | ||
emits: ['update:modelValue', 'update:sort', 'update:expand'], | ||
setup (props, { emit, attrs: $attrs }) { | ||
const { ui, attrs } = useUI('table', toRef(props, 'ui'), config, toRef(props, 'class')) | ||
|
||
|
@@ -349,11 +353,12 @@ export default defineComponent({ | |
return get(row, rowKey, defaultValue) | ||
} | ||
|
||
function toggleOpened (index: number) { | ||
function toggleOpened ({ index, row }: { index: number, row: Row }) { | ||
if (openedRows.value.includes(index)) { | ||
openedRows.value = openedRows.value.filter((i) => i !== index) | ||
} else { | ||
openedRows.value.push(index) | ||
emit('update:expand', { expandedRows: openedRows.value, row }) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this be emitted in both case? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should it? I think it could be either emitted in both cases and the information whether it was an "expand" or "collapse" could be added as a function parameter to the user or there could be another emit like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since you send the |
||
} | ||
} | ||
|
||
|
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.