Skip to content

fix(runtime): fix blur handling of non-scoped elements #6314

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
Jul 10, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
prettier
  • Loading branch information
christian-bromann committed Jul 9, 2025
commit 9d3c7c68fbd76ce7a5799fb0ee35071b9532ff00
7 changes: 0 additions & 7 deletions src/runtime/bootstrap-lazy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { disconnectedCallback } from './disconnected-callback';
import {
patchChildSlotNodes,
patchCloneNode,
patchGlobalAppendChild,
patchPseudoShadowDom,
patchSlotAppendChild,
patchTextContent,
Expand Down Expand Up @@ -62,12 +61,6 @@ export const bootstrapLazy = (lazyBundles: d.LazyBundlesRuntimeData, options: d.
}

let hasSlotRelocation = false;

// Initialize global appendChild patching for blur event suppression
if (BUILD.experimentalSlotFixes) {
patchGlobalAppendChild();
}

lazyBundles.map((lazyBundle) => {
lazyBundle[1].map((compactMeta) => {
const cmpMeta: d.ComponentRuntimeMeta = {
Expand Down
58 changes: 27 additions & 31 deletions src/runtime/dom-extras.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const patchGlobalAppendChild = () => {

const originalAppendChild = Element.prototype.appendChild;

Element.prototype.appendChild = function<T extends Node>(this: Element, newChild: T): T {
Element.prototype.appendChild = function <T extends Node>(this: Element, newChild: T): T {
// Check if we're adding a shadow DOM element (custom element with hyphen) to a non-shadow parent
if (newChild && (newChild as any).tagName && (newChild as any).tagName.includes('-')) {
patchParentNode(newChild);
Expand Down Expand Up @@ -580,12 +580,8 @@ export const patchParentNode = (node: Node) => {
if (node.nodeType === NODE_TYPE.ELEMENT_NODE) {
const element = node as HTMLElement;



// Check if this is a shadow DOM component (has hyphen in tag name and shadowRoot)
if (element.tagName?.includes('-')) {


const originalFocus = element.focus.bind(element);
const originalDispatchEvent = element.dispatchEvent.bind(element);
const originalAddEventListener = element.addEventListener.bind(element);
Expand All @@ -594,42 +590,42 @@ export const patchParentNode = (node: Node) => {
const blurSuppressionWindow = 200; // 200ms window to suppress blur after focus
const blurListeners: Array<{ listener: EventListener; options?: boolean | AddEventListenerOptions }> = [];

// Add global focus tracking as a fallback
const globalFocusHandler = (event: Event) => {
if (event.target === element) {
recordFocusTime();
}
};
const globalClickHandler = (event: Event) => {
if (event.target === element) {
recordFocusTime();
}
};
// Add global focus tracking as a fallback
const globalFocusHandler = (event: Event) => {
if (event.target === element) {
recordFocusTime();
}
};
const globalClickHandler = (event: Event) => {
if (event.target === element) {
recordFocusTime();
}
};

// Add global listeners to catch focus/click events that bypass our patches
document.addEventListener('focus', globalFocusHandler, true);
document.addEventListener('click', globalClickHandler, true);

// Helper function to record focus time
const recordFocusTime = () => {
lastFocusTime = Date.now();
};
const recordFocusTime = () => {
lastFocusTime = Date.now();
};

element.focus = function (options?: FocusOptions) {
// Record the time when focus is called
recordFocusTime();
element.focus = function (options?: FocusOptions) {
// Record the time when focus is called
recordFocusTime();

// Call the original focus method
originalFocus(options);
};
// Call the original focus method
originalFocus(options);
};

element.click = function () {
// Record focus time when click is called, as click often triggers focus
recordFocusTime();
element.click = function () {
// Record focus time when click is called, as click often triggers focus
recordFocusTime();

// Call the original click method
originalClick();
};
// Call the original click method
originalClick();
};

// Intercept addEventListener to wrap blur event listeners and add click/focus tracking
element.addEventListener = function (
Expand Down
16 changes: 6 additions & 10 deletions test/wdio/radio-group-blur/test-radio-group.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ export class TestRadioGroup {
*/
@Event() ionValueChange!: EventEmitter<any>;


@Watch('value')
valueChanged(value: any | undefined) {
this.setRadioTabindex(value);
Expand Down Expand Up @@ -162,15 +161,12 @@ export class TestRadioGroup {

render() {
return (
<Host
role="radiogroup"
onClick={this.onClick}
>
{this.renderHintText()}

{/* Change this to be wrapped in a <div> to fix the issue */}
<slot></slot>
</Host>
<Host role="radiogroup" onClick={this.onClick}>
{this.renderHintText()}

{/* Change this to be wrapped in a <div> to fix the issue */}
<slot></slot>
</Host>
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/wdio/radio-group-blur/test-radio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export class Radio {
<div class="native-wrapper">{this.renderRadioControl()}</div>
</label>
</Host>
)
);
}
}

Expand Down
4 changes: 2 additions & 2 deletions test/wdio/radio-group-blur/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type CompareFn = (currentValue: any, compareValue: any) => boolean;
export const compareOptions = (
currentValue: any,
compareValue: any,
compareWith?: string | CompareFn | null
compareWith?: string | CompareFn | null,
): boolean => {
if (typeof compareWith === 'function') {
return compareWith(currentValue, compareValue);
Expand All @@ -67,7 +67,7 @@ export const compareOptions = (
export const isOptionSelected = (
currentValue: any[] | any,
compareValue: any,
compareWith?: string | CompareFn | null
compareWith?: string | CompareFn | null,
) => {
if (currentValue === undefined) {
return false;
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy