Skip to content

Commit 541abe1

Browse files
committed
Return native JS click event with ipl-button click events
1 parent 0d82c3d commit 541abe1

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
# 3.9.0
22

3+
- Allow adjusting the position of ipl-dialog
34
- Add `autocomplete` and `autofocus` attributes to ipl-input
45
- Set color-scheme CSS property to fix some styling oddities
56
- Add `closeComplete` event to ipl-dialog
67
- Add `select` method to ipl-input
8+
- Return native JS click event with ipl-button click events
9+
- This may be used to determine the clicked DOM element or the click's position
710

811
# 3.8.0
912

src/components/iplButton.vue

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<template>
22
<component
33
:is="hasLink ? 'a' : 'button'"
4+
ref="rootElement"
45
:href="disabledInternal ? undefined : href"
56
:target="hasLink ? '_blank' : undefined"
67
class="ipl-button"
@@ -144,6 +145,7 @@ export default defineComponent({
144145
let resetTimeout: number | null = null;
145146
let confirmationResetTimeout: number | null = null;
146147
const buttonState: Ref<'idle' | 'error' | 'success' | 'loading'> = ref('idle');
148+
const rootElement = ref<HTMLElement>();
147149
const setState = (state: 'error' | 'success') => {
148150
buttonState.value = state;
149151
if (resetTimeout !== null) {
@@ -193,7 +195,7 @@ export default defineComponent({
193195
color: textColor.value
194196
});
195197
}),
196-
async handleClick(event: Event) {
198+
async handleClick(event: MouseEvent) {
197199
if (disabledInternal.value) {
198200
return;
199201
}
@@ -215,7 +217,12 @@ export default defineComponent({
215217
}
216218
217219
if (!props.async && !props.disableOnSuccess) {
218-
emit('click');
220+
// Pretend the target was always the root button element.
221+
// There might be a really good reason not to do this I haven't found yet,
222+
// but at the moment I found it wasn't useful to specify whether the
223+
// element that was pressed was the button or its label.
224+
Object.defineProperty(event, 'target', { value: rootElement.value });
225+
emit('click', event);
219226
} else {
220227
try {
221228
if (props.async) {
@@ -245,7 +252,8 @@ export default defineComponent({
245252
return buttonState.value;
246253
}),
247254
isBlank,
248-
hasLink
255+
hasLink,
256+
rootElement
249257
};
250258
}
251259
});

0 commit comments

Comments
 (0)