Skip to content

Commit 6ae2907

Browse files
fix(picker-column): fallback to elementFromPoint for iOS 16 Shadow DOM bug (#30479)
Issue number: resolves #29672 --------- <!-- Please do not submit updates to dependencies unless it fixes an issue. --> <!-- Please try to limit your pull request to one type (bugfix, feature, etc). Submit multiple pull requests if needed. --> ## What is the current behavior? <!-- Please describe the current behavior that you are modifying. --> The issue on iOS 16 with `elementsFromPoint` is related to how it handles Shadow DOM retargeting when called from the document (global) context. It leads to an `undefined` element that is required to trigger `ionChange`. ## What is the new behavior? <!-- Please describe the behavior or changes that are being added by this PR. --> - Returns the top most element as a fallback only if the element has a tag of `'ion-picker-column-option'`. ## Does this introduce a breaking change? - [ ] Yes - [x] No <!-- If this introduces a breaking change: 1. Describe the impact and migration path for existing applications below. 2. Update the BREAKING.md file with the breaking change. 3. Add "BREAKING CHANGE: [...]" to the commit description when merging. See https://github.com/ionic-team/ionic-framework/blob/main/docs/CONTRIBUTING.md#footer for more information. --> ## Other information <!-- Any other information that is important to this PR such as screenshots of how the component looks before and after the change. --> Dev build: `8.6.2-dev.11749761258.1b46b6a9` --------- Co-authored-by: Vilhelm Josander <[email protected]>
1 parent 6811fe5 commit 6ae2907

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

core/src/components/picker-column/picker-column.tsx

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,27 @@ export class PickerColumn implements ComponentInterface {
376376
* elementsFromPoint can returns multiple elements
377377
* so find the relevant picker column option if one exists.
378378
*/
379-
const newActiveElement = elementsAtPoint.find((el) => el.tagName === 'ION-PICKER-COLUMN-OPTION');
379+
let newActiveElement = elementsAtPoint.find((el) => el.tagName === 'ION-PICKER-COLUMN-OPTION');
380+
381+
/**
382+
* TODO(FW-6594): Remove this workaround when iOS 16 is no longer
383+
* supported.
384+
*
385+
* If `elementsFromPoint` failed to find the active element (a known
386+
* issue on iOS 16 when elements are in a Shadow DOM and the
387+
* referenceNode is the document), a fallback to `elementFromPoint`
388+
* is used. While `elementsFromPoint` returns all elements,
389+
* `elementFromPoint` returns only the top-most, which is sufficient
390+
* for this use case and appears to handle Shadow DOM retargeting
391+
* more reliably in this specific iOS bug.
392+
*/
393+
if (newActiveElement === undefined) {
394+
const fallbackActiveElement = referenceNode.elementFromPoint(centerX, centerY);
395+
396+
if (fallbackActiveElement?.tagName === 'ION-PICKER-COLUMN-OPTION') {
397+
newActiveElement = fallbackActiveElement as HTMLIonPickerColumnOptionElement;
398+
}
399+
}
380400

381401
if (activeEl !== undefined) {
382402
this.setPickerItemActiveState(activeEl, false);

0 commit comments

Comments
 (0)