Skip to content

Commit

Permalink
fix(select): prevent clicks on non-interactive elements inside ion-se…
Browse files Browse the repository at this point in the history
…lect to ensure correct popover size (#697)
  • Loading branch information
felipefialho authored Feb 4, 2025
1 parent 53716d7 commit 02200ec
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/core/src/components/select/select.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,9 +347,9 @@ describe('AtomSelect', () => {

await page.waitForChanges()
const mockFiltered = optionsMock.filter((option) => option?.tag?.label)
const instanceObjetct = page.rootInstance.filterOptionsWithTag(optionsMock)
const instanceObject = page.rootInstance.filterOptionsWithTag(optionsMock)

expect(Object.keys(instanceObjetct).length).toEqual(mockFiltered.length)
expect(Object.keys(instanceObject).length).toEqual(mockFiltered.length)
})
it('should filter options and attach tag element', async () => {
const page = await newSpecPage({
Expand Down
17 changes: 17 additions & 0 deletions packages/core/src/components/select/select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,29 @@ export class AtomSelect {

componentDidLoad() {
this.selectEl.addEventListener('ionDismiss', this.handleDismiss)
this.applyPointerEventsNone()
}

disconnectedCallback() {
this.selectEl.removeEventListener('ionDismiss', this.handleDismiss)
}

/*
* In some cases, individual elements inside `ion-select` are clickable, causing the popover to open with an incorrect size.
* For example, clicking on the arrow icon can result in a very small options overlay, leading to a poor user experience.
* This method is a workaround to fix this issue by adding `pointer-events: none` to elements inside the `ion-select`
* that are not the `label` or `icon`, ensuring a consistent overlay size.
*/
private applyPointerEventsNone() {
const ionSelect = this.selectEl?.shadowRoot?.querySelector('ion-select')
const selectWrapper =
ionSelect?.shadowRoot?.querySelector('.select-wrapper')

if (selectWrapper) {
(selectWrapper as HTMLElement).style.pointerEvents = 'none'
}
}

private handleChange: IonTypes.IonSelect['onIonChange'] = (event) => {
this.value = event.detail.value
this.atomChange.emit(this.value)
Expand Down

0 comments on commit 02200ec

Please sign in to comment.