Skip to content

Commit 5952880

Browse files
committed
fix: make padding for actions with custom renderers clickable
https://web.tracklify.com/project/2b7ZVgE5/AdminForth/1394/7dhmHy1b/click-area-is-broken:
1 parent a9aa90e commit 5952880

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

adminforth/documentation/docs/tutorial/03-Customization/09-Actions.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ Keep the `<slot />` (that's where AdminForth renders the default button) and emi
224224
<!-- Keep the slot: AdminForth renders the default action button/icon here -->
225225
<!-- Emit `callAction` (optionally with a payload) to trigger the action when the wrapper is clicked -->
226226
<!-- Example: provide `meta.extra` to send custom data. In list views we merge with `row` so recordId context is kept. -->
227-
<div :style="styleObj" @click="emit('callAction', { ...props.row, ...(props.meta?.extra ?? {}) })">
227+
<div :style="styleObj" @click="click({ ...props.row, ...(props.meta?.extra ?? {}) })">
228228
<slot />
229229
</div>
230230
</template>
@@ -248,6 +248,14 @@ const styleObj = computed(() => ({
248248
borderRadius: (props.meta?.radius ?? 8) + 'px',
249249
padding: (props.meta?.padding ?? 2) + 'px',
250250
}));
251+
252+
function click(payload: any) {
253+
emit('callAction', { ...props.row, ...(props.meta?.extra ?? {}) })
254+
}
255+
//we need to define this expose, because padding is added by adminforth wrapper and to trigger click on this padding we use this expose
256+
defineExpose({
257+
click
258+
});
251259
</script>
252260
```
253261

adminforth/spa/src/components/ThreeDotsMenu.vue

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,17 @@
4343
</div>
4444
</div>
4545
</li>
46-
<li v-for="action in customActions" :key="action.id">
47-
<div class="wrapper">
46+
<li v-for="(action, i) in customActions" :key="action.id">
47+
<div
48+
class="wrapper"
49+
@click="injectedComponentClick(threeDotsDropdownItems ? threeDotsDropdownItems.length + i : i)"
50+
>
4851
<component
52+
:ref="(el: any) => setComponentRef(el, threeDotsDropdownItems ? threeDotsDropdownItems.length + i : i)"
4953
:is="(action.customComponent && getCustomComponent(formatComponent(action.customComponent))) || CallActionWrapper"
5054
:meta="formatComponent(action.customComponent).meta"
5155
@callAction="(payload? : Object) => handleActionClick(action, payload)"
52-
>
56+
] >
5357
<a @click.prevent class="block">
5458
<div class="flex items-center gap-2 hover:text-lightThreeDotsMenuBodyTextHover hover:bg-lightThreeDotsMenuBodyBackgroundHover dark:hover:bg-darkThreeDotsMenuBodyBackgroundHover dark:hover:text-darkThreeDotsMenuBodyTextHover">
5559
<component
@@ -173,6 +177,7 @@ function startBulkAction(actionId: string) {
173177
}
174178
175179
async function injectedComponentClick(index: number) {
180+
console.log('Injected component click triggered for index:', index);
176181
const componentRef = threeDotsDropdownItemsRefs.value[index];
177182
if (componentRef && 'click' in componentRef) {
178183
(componentRef as any).click?.();

dev-demo/custom/RequireTwoFaGate.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,8 @@
1515
const verificationResult = await modal.get2FaConfirmationResult();
1616
emit('callAction', { verificationResult } );
1717
}
18+
19+
defineExpose({
20+
click: onClick
21+
});
1822
</script>

0 commit comments

Comments
 (0)