Skip to content

Commit ee3467c

Browse files
authored
perf(item): remove delegatesFocus patch for iOS 13 (#25822)
1 parent 1eb6fd0 commit ee3467c

File tree

5 files changed

+4
-129
lines changed

5 files changed

+4
-129
lines changed

core/src/components.d.ts

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,10 +1076,6 @@ export namespace Components {
10761076
* A hint to the browser for which enter key to display. Possible values: `"enter"`, `"done"`, `"go"`, `"next"`, `"previous"`, `"search"`, and `"send"`.
10771077
*/
10781078
"enterkeyhint"?: 'enter' | 'done' | 'go' | 'next' | 'previous' | 'search' | 'send';
1079-
/**
1080-
* This is required for a WebKit bug which requires us to blur and focus an input to properly focus the input in an item with delegatesFocus. It will no longer be needed with iOS 14.
1081-
*/
1082-
"fireFocusEvents": boolean;
10831079
/**
10841080
* Returns the native `<input>` element used under the hood.
10851081
*/
@@ -1132,10 +1128,6 @@ export namespace Components {
11321128
* If `true`, the user must fill in a value before submitting a form.
11331129
*/
11341130
"required": boolean;
1135-
/**
1136-
* Sets blur on the native `input` in `ion-input`. Use this method instead of the global `input.blur()`.
1137-
*/
1138-
"setBlur": () => Promise<void>;
11391131
/**
11401132
* Sets focus on the native `input` in `ion-input`. Use this method instead of the global `input.focus()`.
11411133
*/
@@ -2842,10 +2834,6 @@ export namespace Components {
28422834
* A hint to the browser for which enter key to display. Possible values: `"enter"`, `"done"`, `"go"`, `"next"`, `"previous"`, `"search"`, and `"send"`.
28432835
*/
28442836
"enterkeyhint"?: 'enter' | 'done' | 'go' | 'next' | 'previous' | 'search' | 'send';
2845-
/**
2846-
* This is required for a WebKit bug which requires us to blur and focus an input to properly focus the input in an item with delegatesFocus. It will no longer be needed with iOS 14.
2847-
*/
2848-
"fireFocusEvents": boolean;
28492837
/**
28502838
* Returns the native `<textarea>` element used under the hood.
28512839
*/
@@ -2886,10 +2874,6 @@ export namespace Components {
28862874
* The number of visible text lines for the control.
28872875
*/
28882876
"rows"?: number;
2889-
/**
2890-
* Sets blur on the native `textarea` in `ion-textarea`. Use this method instead of the global `textarea.blur()`.
2891-
*/
2892-
"setBlur": () => Promise<void>;
28932877
/**
28942878
* Sets focus on the native `textarea` in `ion-textarea`. Use this method instead of the global `textarea.focus()`.
28952879
*/
@@ -4990,10 +4974,6 @@ declare namespace LocalJSX {
49904974
* A hint to the browser for which enter key to display. Possible values: `"enter"`, `"done"`, `"go"`, `"next"`, `"previous"`, `"search"`, and `"send"`.
49914975
*/
49924976
"enterkeyhint"?: 'enter' | 'done' | 'go' | 'next' | 'previous' | 'search' | 'send';
4993-
/**
4994-
* This is required for a WebKit bug which requires us to blur and focus an input to properly focus the input in an item with delegatesFocus. It will no longer be needed with iOS 14.
4995-
*/
4996-
"fireFocusEvents"?: boolean;
49974977
/**
49984978
* A hint to the browser for which keyboard to display. Possible values: `"none"`, `"text"`, `"tel"`, `"url"`, `"email"`, `"numeric"`, `"decimal"`, and `"search"`.
49994979
*/
@@ -6751,10 +6731,6 @@ declare namespace LocalJSX {
67516731
* A hint to the browser for which enter key to display. Possible values: `"enter"`, `"done"`, `"go"`, `"next"`, `"previous"`, `"search"`, and `"send"`.
67526732
*/
67536733
"enterkeyhint"?: 'enter' | 'done' | 'go' | 'next' | 'previous' | 'search' | 'send';
6754-
/**
6755-
* This is required for a WebKit bug which requires us to blur and focus an input to properly focus the input in an item with delegatesFocus. It will no longer be needed with iOS 14.
6756-
*/
6757-
"fireFocusEvents"?: boolean;
67586734
/**
67596735
* A hint to the browser for which keyboard to display. Possible values: `"none"`, `"text"`, `"tel"`, `"url"`, `"email"`, `"numeric"`, `"decimal"`, and `"search"`.
67606736
*/

core/src/components/input/input.tsx

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,6 @@ export class Input implements ComponentInterface {
3131
private inheritedAttributes: Attributes = {};
3232
private isComposing = false;
3333

34-
/**
35-
* This is required for a WebKit bug which requires us to
36-
* blur and focus an input to properly focus the input in
37-
* an item with delegatesFocus. It will no longer be needed
38-
* with iOS 14.
39-
*
40-
* @internal
41-
*/
42-
@Prop() fireFocusEvents = true;
43-
4434
@State() hasFocus = false;
4535

4636
@Element() el!: HTMLElement;
@@ -312,18 +302,6 @@ export class Input implements ComponentInterface {
312302
}
313303
}
314304

315-
/**
316-
* Sets blur on the native `input` in `ion-input`. Use this method instead of the global
317-
* `input.blur()`.
318-
* @internal
319-
*/
320-
@Method()
321-
async setBlur() {
322-
if (this.nativeInput) {
323-
this.nativeInput.blur();
324-
}
325-
}
326-
327305
/**
328306
* Returns the native `<input>` element used under the hood.
329307
*/
@@ -365,19 +343,15 @@ export class Input implements ComponentInterface {
365343
this.focusChanged();
366344
this.emitStyle();
367345

368-
if (this.fireFocusEvents) {
369-
this.ionBlur.emit(ev);
370-
}
346+
this.ionBlur.emit(ev);
371347
};
372348

373349
private onFocus = (ev: FocusEvent) => {
374350
this.hasFocus = true;
375351
this.focusChanged();
376352
this.emitStyle();
377353

378-
if (this.fireFocusEvents) {
379-
this.ionFocus.emit(ev);
380-
}
354+
this.ionFocus.emit(ev);
381355
};
382356

383357
private onKeydown = (ev: KeyboardEvent) => {

core/src/components/item/item.tsx

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ import type { CounterFormatter } from './item-interface';
3737
export class Item implements ComponentInterface, AnchorInterface, ButtonInterface {
3838
private labelColorStyles = {};
3939
private itemStyles = new Map<string, CssClassMap>();
40-
private clickListener?: (ev: Event) => void;
4140

4241
@Element() el!: HTMLIonItemElement;
4342

@@ -205,25 +204,6 @@ export class Item implements ComponentInterface, AnchorInterface, ButtonInterfac
205204
this.hasStartEl();
206205
}
207206

208-
componentDidUpdate() {
209-
// Do not use @Listen here to avoid making all items
210-
// appear as clickable to screen readers
211-
// https://github.com/ionic-team/ionic-framework/issues/22011
212-
const input = this.getFirstInput();
213-
if (input && !this.clickListener) {
214-
this.clickListener = (ev: Event) => this.delegateFocus(ev, input);
215-
this.el.addEventListener('click', this.clickListener);
216-
}
217-
}
218-
219-
disconnectedCallback() {
220-
const input = this.getFirstInput();
221-
if (input && this.clickListener) {
222-
this.el.removeEventListener('click', this.clickListener);
223-
this.clickListener = undefined;
224-
}
225-
}
226-
227207
componentDidLoad() {
228208
raf(() => {
229209
this.setMultipleInputs();
@@ -287,33 +267,6 @@ export class Item implements ComponentInterface, AnchorInterface, ButtonInterfac
287267
return inputs[0];
288268
}
289269

290-
// This is needed for WebKit due to a delegatesFocus bug where
291-
// clicking on the left padding of an item is not focusing the input
292-
// but is opening the keyboard. It will no longer be needed with
293-
// iOS 14.
294-
private delegateFocus(ev: Event, input: HTMLIonInputElement | HTMLIonTextareaElement) {
295-
const clickedItem = (ev.target as HTMLElement).tagName === 'ION-ITEM';
296-
let firstActive = false;
297-
298-
// If the first input is the same as the active element we need
299-
// to focus the first input again, but if the active element
300-
// is another input inside of the item we shouldn't switch focus
301-
if (document.activeElement) {
302-
firstActive = input.querySelector('input, textarea') === document.activeElement;
303-
}
304-
305-
// Only focus the first input if we clicked on an ion-item
306-
// and the first input exists
307-
if (clickedItem && (firstActive || !this.multipleInputs)) {
308-
input.fireFocusEvents = false;
309-
input.setBlur();
310-
input.setFocus();
311-
raf(() => {
312-
input.fireFocusEvents = true;
313-
});
314-
}
315-
}
316-
317270
private updateCounterOutput(inputEl: HTMLIonInputElement | HTMLIonTextareaElement) {
318271
const { counter, counterFormatter, defaultCounterFormatter } = this;
319272
if (counter && !this.multipleInputs && inputEl?.maxlength !== undefined) {

core/src/components/textarea/textarea.tsx

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,6 @@ export class Textarea implements ComponentInterface {
2525
private textareaWrapper?: HTMLElement;
2626
private inheritedAttributes: Attributes = {};
2727

28-
/**
29-
* This is required for a WebKit bug which requires us to
30-
* blur and focus an input to properly focus the input in
31-
* an item with delegatesFocus. It will no longer be needed
32-
* with iOS 14.
33-
*
34-
* @internal
35-
*/
36-
@Prop() fireFocusEvents = true;
37-
3828
@Element() el!: HTMLElement;
3929

4030
@State() hasFocus = false;
@@ -242,18 +232,6 @@ export class Textarea implements ComponentInterface {
242232
}
243233
}
244234

245-
/**
246-
* Sets blur on the native `textarea` in `ion-textarea`. Use this method instead of the global
247-
* `textarea.blur()`.
248-
* @internal
249-
*/
250-
@Method()
251-
async setBlur() {
252-
if (this.nativeInput) {
253-
this.nativeInput.blur();
254-
}
255-
}
256-
257235
/**
258236
* Returns the native `<textarea>` element used under the hood.
259237
*/
@@ -332,18 +310,14 @@ export class Textarea implements ComponentInterface {
332310
this.hasFocus = true;
333311
this.focusChange();
334312

335-
if (this.fireFocusEvents) {
336-
this.ionFocus.emit(ev);
337-
}
313+
this.ionFocus.emit(ev);
338314
};
339315

340316
private onBlur = (ev: FocusEvent) => {
341317
this.hasFocus = false;
342318
this.focusChange();
343319

344-
if (this.fireFocusEvents) {
345-
this.ionBlur.emit(ev);
346-
}
320+
this.ionBlur.emit(ev);
347321
};
348322

349323
private onKeyDown = () => {

packages/vue/src/proxies.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,6 @@ export const IonInfiniteScrollContent = /*@__PURE__*/ defineContainer<JSX.IonInf
386386

387387

388388
export const IonInput = /*@__PURE__*/ defineContainer<JSX.IonInput>('ion-input', defineIonInput, [
389-
'fireFocusEvents',
390389
'color',
391390
'accept',
392391
'autocapitalize',
@@ -781,7 +780,6 @@ export const IonText = /*@__PURE__*/ defineContainer<JSX.IonText>('ion-text', de
781780

782781

783782
export const IonTextarea = /*@__PURE__*/ defineContainer<JSX.IonTextarea>('ion-textarea', defineIonTextarea, [
784-
'fireFocusEvents',
785783
'color',
786784
'autocapitalize',
787785
'autofocus',

0 commit comments

Comments
 (0)