Skip to content

Commit 47aab6c

Browse files
committed
fix(input): fixing issue where clicking on the input wrapper would trigger onclick twice
1 parent dbc2f10 commit 47aab6c

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

core/src/components/input/input.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,7 @@ export class Input implements ComponentInterface {
829829
*/}
830830
<label class="input-wrapper" htmlFor={inputId} onClick={this.onLabelClick}>
831831
{this.renderLabelContainer()}
832-
<div class="native-wrapper">
832+
<div class="native-wrapper" onClick={this.onLabelClick}>
833833
<slot name="start"></slot>
834834
<input
835835
class="native-input"

core/src/components/input/test/basic/input.e2e.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,5 +164,38 @@ configs({ modes: ['ios'], directions: ['ltr'] }).forEach(({ title, screenshot, c
164164
const event = clickEvent.events[0];
165165
expect((event.target as HTMLElement).tagName.toLowerCase()).toBe('ion-input');
166166
});
167+
168+
test('should trigger onclick only once when clicking the wrapper', async ({ page }) => {
169+
// Create a spy function in page context
170+
await page.setContent(
171+
`
172+
<ion-input
173+
label="Click Me"
174+
value="Test Value"
175+
></ion-input>
176+
`,
177+
config
178+
);
179+
180+
// Track calls to the exposed function
181+
const clickEvent = await page.spyOnEvent('click');
182+
const input = page.locator('div.native-wrapper');
183+
184+
// Use position to make sure we click into the label enough to trigger
185+
// what would be the double click
186+
await input.click({
187+
position: {
188+
x: 5,
189+
y: 5,
190+
},
191+
});
192+
193+
// Verify the click was triggered exactly once
194+
expect(clickEvent).toHaveReceivedEventTimes(1);
195+
196+
// Verify that the event target is the checkbox and not the item
197+
const event = clickEvent.events[0];
198+
expect((event.target as HTMLElement).tagName.toLowerCase()).toBe('ion-input');
199+
});
167200
});
168201
});

0 commit comments

Comments
 (0)