Skip to content

Commit 5560dcd

Browse files
committed
fix(all): avoid using focus() since it conflicts with HTMLElement
fixes #15810
1 parent 6a5aec8 commit 5560dcd

File tree

10 files changed

+28
-23
lines changed

10 files changed

+28
-23
lines changed

angular/src/directives/proxies.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ export class Input {
356356

357357
constructor(r: ElementRef) {
358358
const el = r.nativeElement;
359-
proxyMethods(this, el, ['focus']);
359+
proxyMethods(this, el, ['setFocus']);
360360
proxyInputs(this, el, ['color', 'mode', 'accept', 'autocapitalize', 'autocomplete', 'autocorrect', 'autofocus', 'clearInput', 'clearOnEdit', 'debounce', 'disabled', 'inputmode', 'max', 'maxlength', 'min', 'minlength', 'multiple', 'name', 'pattern', 'placeholder', 'readonly', 'required', 'results', 'spellcheck', 'step', 'size', 'type', 'value']);
361361
proxyOutputs(this, el, ['ionInput', 'ionChange', 'ionStyle', 'ionBlur', 'ionFocus', 'ionInputDidLoad', 'ionInputDidUnload']);
362362
}
@@ -654,7 +654,7 @@ export class Searchbar {
654654

655655
constructor(r: ElementRef) {
656656
const el = r.nativeElement;
657-
proxyMethods(this, el, ['focus']);
657+
proxyMethods(this, el, ['setFocus']);
658658
proxyInputs(this, el, ['color', 'mode', 'animated', 'autocomplete', 'autocorrect', 'cancelButtonIcon', 'cancelButtonText', 'clearIcon', 'debounce', 'placeholder', 'searchIcon', 'showCancelButton', 'spellcheck', 'type', 'value']);
659659
proxyOutputs(this, el, ['ionInput', 'ionChange', 'ionCancel', 'ionClear', 'ionBlur', 'ionFocus']);
660660
}
@@ -857,7 +857,7 @@ export class Textarea {
857857

858858
constructor(r: ElementRef) {
859859
const el = r.nativeElement;
860-
proxyMethods(this, el, ['focus']);
860+
proxyMethods(this, el, ['setFocus']);
861861
proxyInputs(this, el, ['mode', 'color', 'autocapitalize', 'autofocus', 'clearOnEdit', 'debounce', 'disabled', 'maxlength', 'minlength', 'name', 'placeholder', 'readonly', 'required', 'spellcheck', 'cols', 'rows', 'wrap', 'value']);
862862
proxyOutputs(this, el, ['ionChange', 'ionInput', 'ionStyle', 'ionBlur', 'ionFocus']);
863863
}

core/src/components.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1733,7 +1733,6 @@ export namespace Components {
17331733
* If true, the user cannot interact with the input. Defaults to `false`.
17341734
*/
17351735
'disabled': boolean;
1736-
'focus': () => void;
17371736
/**
17381737
* A hint to the browser for which keyboard to display. This attribute applies when the value of the type attribute is `"text"`, `"password"`, `"email"`, or `"url"`. Possible values are: `"verbatim"`, `"latin"`, `"latin-name"`, `"latin-prose"`, `"full-width-latin"`, `"kana"`, `"katakana"`, `"numeric"`, `"tel"`, `"email"`, `"url"`.
17391738
*/
@@ -1786,6 +1785,7 @@ export namespace Components {
17861785
* This is a nonstandard attribute supported by Safari that only applies when the type is `"search"`. Its value should be a nonnegative decimal integer.
17871786
*/
17881787
'results'?: number;
1788+
'setFocus': () => void;
17891789
/**
17901790
* The initial size of the control. This value is in pixels unless the value of the type attribute is `"text"` or `"password"`, in which case it is an integer number of characters. This attribute applies only when the `type` attribute is set to `"text"`, `"search"`, `"tel"`, `"url"`, `"email"`, or `"password"`, otherwise it is ignored.
17911791
*/
@@ -3713,7 +3713,6 @@ export namespace Components {
37133713
* Set the amount of time, in milliseconds, to wait to trigger the `ionChange` event after each keystroke. Default `250`.
37143714
*/
37153715
'debounce': number;
3716-
'focus': () => void;
37173716
/**
37183717
* The mode determines which platform styles to use. Possible values are: `"ios"` or `"md"`.
37193718
*/
@@ -3726,6 +3725,7 @@ export namespace Components {
37263725
* The icon to use as the search icon. Defaults to `"search"`.
37273726
*/
37283727
'searchIcon'?: string;
3728+
'setFocus': () => void;
37293729
/**
37303730
* If true, show the cancel button. Default `false`.
37313731
*/
@@ -4729,7 +4729,6 @@ export namespace Components {
47294729
* If true, the user cannot interact with the textarea. Defaults to `false`.
47304730
*/
47314731
'disabled': boolean;
4732-
'focus': () => void;
47334732
/**
47344733
* If the value of the type attribute is `text`, `email`, `search`, `password`, `tel`, or `url`, this attribute specifies the maximum number of characters that the user can enter.
47354734
*/
@@ -4762,6 +4761,7 @@ export namespace Components {
47624761
* The number of visible text lines for the control.
47634762
*/
47644763
'rows'?: number;
4764+
'setFocus': () => void;
47654765
/**
47664766
* If true, the element will have its spelling and grammar checked. Defaults to `false`.
47674767
*/

core/src/components/input/input.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ export class Input implements ComponentInterface {
245245
}
246246

247247
@Method()
248-
focus() {
248+
setFocus() {
249249
if (this.nativeInput) {
250250
this.nativeInput.focus();
251251
}

core/src/components/input/readme.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ It is meant for text `type` inputs only, such as `"text"`, `"password"`, `"email
5757

5858
## Methods
5959

60-
| Method | Description |
61-
| ------- | ----------- |
62-
| `focus` | |
60+
| Method | Description |
61+
| ---------- | ----------- |
62+
| `setFocus` | |
6363

6464

6565
----------------------------------------------

core/src/components/searchbar/readme.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ A Searchbar should be used instead of an input to search lists. A clear button i
4444

4545
## Methods
4646

47-
| Method | Description |
48-
| ------- | ----------- |
49-
| `focus` | |
47+
| Method | Description |
48+
| ---------- | ----------- |
49+
| `setFocus` | |
5050

5151

5252
## CSS Custom Properties

core/src/components/searchbar/searchbar.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ export class Searchbar implements ComponentInterface {
141141
protected valueChanged() {
142142
const inputEl = this.nativeInput;
143143
const value = this.value;
144-
if (inputEl.value !== value) {
144+
if (inputEl && inputEl.value !== value) {
145145
inputEl.value = value;
146146
}
147147
this.ionChange.emit({ value });
@@ -153,8 +153,10 @@ export class Searchbar implements ComponentInterface {
153153
}
154154

155155
@Method()
156-
focus() {
157-
this.nativeInput.focus();
156+
setFocus() {
157+
if (this.nativeInput) {
158+
this.nativeInput.focus();
159+
}
158160
}
159161

160162
/**

core/src/components/textarea/readme.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ The textarea component accepts the [native textarea attributes](https://develope
4848

4949
## Methods
5050

51-
| Method | Description |
52-
| ------- | ----------- |
53-
| `focus` | |
51+
| Method | Description |
52+
| ---------- | ----------- |
53+
| `setFocus` | |
5454

5555

5656
## CSS Custom Properties

core/src/components/textarea/textarea.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ export class Textarea implements ComponentInterface {
169169
}
170170

171171
@Method()
172-
focus() {
172+
setFocus() {
173173
if (this.nativeInput) {
174174
this.nativeInput.focus();
175175
}

core/src/global/config.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@ export class Config {
3434
}
3535
}
3636

37-
const IONIC_PREFIX = 'ionic:';
38-
const IONIC_SESSION_KEY = 'ionic-persist-config';
39-
4037
export function configFromSession(): any {
4138
try {
4239
const configStr = window.sessionStorage.getItem(IONIC_SESSION_KEY);
@@ -73,3 +70,6 @@ export function configFromURL() {
7370
function startsWith(input: string, search: string): boolean {
7471
return input.substr(0, search.length) === search;
7572
}
73+
74+
const IONIC_PREFIX = 'ionic:';
75+
const IONIC_SESSION_KEY = 'ionic-persist-config';

core/src/utils/overlays-interface.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ export interface HTMLIonOverlayElement extends HTMLStencilElement {
4343
dismiss(data?: any, role?: string): Promise<boolean>;
4444
}
4545

46+
// TODO: uncomment when TS 3.0 issues are fixed
4647
// Overlay checks
48+
/*
4749
export type Conforms<T extends Required<B>, B> = T;
4850
export type HTMLOverlaysElement =
4951
Conforms<Required<HTMLIonModalElement>, ModalOptions> |
@@ -53,3 +55,4 @@ export type HTMLOverlaysElement =
5355
Conforms<Required<HTMLIonPopoverElement>, PopoverOptions> |
5456
Conforms<Required<HTMLIonPickerElement>, PickerOptions> |
5557
Conforms<Required<HTMLIonLoadingElement>, LoadingOptions>;
58+
*/

0 commit comments

Comments
 (0)