Skip to content

Commit c5c35b3

Browse files
committed
fix: update focus methods to use Promise.resolve for consistency
1 parent c237e6c commit c5c35b3

File tree

31 files changed

+54
-54
lines changed

31 files changed

+54
-54
lines changed

packages/components/src/components/accordion/shadow.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export class KolAccordion implements AccordionAPI, FocusableElement {
5454
*/
5555
@Method()
5656
public async focus(): Promise<void> {
57-
return delegateFocus(this.host!, async () => this.buttonWcRef?.focus?.());
57+
return delegateFocus(this.host!, () => Promise.resolve(this.buttonWcRef?.focus?.()));
5858
}
5959

6060
private handleOnClick = (event: MouseEvent) => {

packages/components/src/components/badge/shadow.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export class KolBadge implements BadgeAPI, FocusableElement {
5858
*/
5959
@Method()
6060
public async focus(): Promise<void> {
61-
return delegateFocus(this.host!, async () => this.smartButtonRef?.focus?.());
61+
return delegateFocus(this.host!, () => Promise.resolve(this.smartButtonRef?.focus?.()));
6262
}
6363

6464
public render(): JSX.Element {

packages/components/src/components/button-link/shadow.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export class KolButtonLink implements ButtonLinkProps, FocusableElement {
6363
*/
6464
@Method()
6565
public async focus(): Promise<void> {
66-
return delegateFocus(this.host!, async () => this.buttonWcRef?.focus?.());
66+
return delegateFocus(this.host!, () => Promise.resolve(this.buttonWcRef?.focus?.()));
6767
}
6868

6969
public render(): JSX.Element {

packages/components/src/components/button/component.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,12 @@ export class KolButtonWc implements ButtonAPI {
8080
return setFocus(this.buttonRef!);
8181
}
8282

83-
private readonly setButtonRef = (ref: HTMLButtonElement | null) => {
84-
this.buttonRef = ref || undefined;
83+
private readonly setButtonRef = (ref?: HTMLButtonElement) => {
84+
this.buttonRef = ref;
8585
};
8686

87-
private readonly setTooltipRef = (ref: HTMLKolTooltipWcElement | null) => {
88-
this.tooltipRef = ref || undefined;
87+
private readonly setTooltipRef = (ref?: HTMLKolTooltipWcElement) => {
88+
this.tooltipRef = ref;
8989
};
9090

9191
private readonly hideTooltip = () => {

packages/components/src/components/button/shadow.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ export class KolButton implements ButtonProps, FocusableElement {
3737
@Element() private readonly host?: HTMLKolButtonElement;
3838
private buttonWcRef?: HTMLKolButtonWcElement;
3939

40-
private readonly setButtonWcRef = (ref: HTMLKolButtonWcElement | null) => {
41-
this.buttonWcRef = ref || undefined;
40+
private readonly setButtonWcRef = (ref?: HTMLKolButtonWcElement) => {
41+
this.buttonWcRef = ref;
4242
};
4343

4444
/**
@@ -55,7 +55,7 @@ export class KolButton implements ButtonProps, FocusableElement {
5555
*/
5656
@Method()
5757
public async focus(): Promise<void> {
58-
return delegateFocus(this.host!, async () => this.buttonWcRef?.focus?.());
58+
return delegateFocus(this.host!, () => Promise.resolve(this.buttonWcRef?.focus?.()));
5959
}
6060

6161
public render(): JSX.Element {

packages/components/src/components/combobox/shadow.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import type {
3535
import type { EventDetail } from '../../schema/interfaces/EventDetail';
3636
import clsx from '../../utils/clsx';
3737
import { nonce } from '../../utils/dev.utils';
38-
import { delegateFocus } from '../../utils/element-focus';
38+
import { delegateFocus, setFocus } from '../../utils/element-focus';
3939
import { ComboboxController } from './controller';
4040

4141
/**
@@ -69,7 +69,7 @@ export class KolCombobox implements ComboboxAPI, FocusableElement {
6969
*/
7070
@Method()
7171
public async focus() {
72-
return delegateFocus(this.host!, async () => this.refInput?.focus?.());
72+
return delegateFocus(this.host!, () => setFocus(this.refInput!));
7373
}
7474

7575
private toggleListbox = () => {

packages/components/src/components/details/shadow.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export class KolDetails implements DetailsAPI, FocusableElement {
4040
*/
4141
@Method()
4242
public async focus(): Promise<void> {
43-
return delegateFocus(this.host!, async () => this.buttonWcRef?.focus?.());
43+
return delegateFocus(this.host!, () => Promise.resolve(this.buttonWcRef?.focus?.()));
4444
}
4545

4646
private toggleTimeout?: ReturnType<typeof setTimeout>;

packages/components/src/components/input-checkbox/shadow.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import type {
2727
} from '../../schema';
2828

2929
import { nonce } from '../../utils/dev.utils';
30-
import { delegateFocus } from '../../utils/element-focus';
30+
import { delegateFocus, setFocus } from '../../utils/element-focus';
3131
import { InputCheckboxController } from './controller';
3232

3333
import KolCheckboxStateWrapperFc, { type CheckboxStateWrapperProps } from '../../functional-component-wrappers/CheckboxStateWrapper/CheckboxStateWrapper';
@@ -76,7 +76,7 @@ export class KolInputCheckbox implements InputCheckboxAPI, FocusableElement {
7676
*/
7777
@Method()
7878
public async focus() {
79-
return delegateFocus(this.host!, async () => this.inputRef?.focus?.());
79+
return delegateFocus(this.host!, () => setFocus(this.inputRef!));
8080
}
8181

8282
private getFormFieldProps(): FormFieldStateWrapperProps {

packages/components/src/components/input-color/shadow.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import KolFormFieldStateWrapperFc, { type FormFieldStateWrapperProps } from '../
2626
import KolInputContainerFc from '../../functional-component-wrappers/InputContainerStateWrapper/InputContainerStateWrapper';
2727
import KolInputStateWrapperFc, { type InputStateWrapperProps } from '../../functional-component-wrappers/InputStateWrapper/InputStateWrapper';
2828
import { nonce } from '../../utils/dev.utils';
29-
import { delegateFocus } from '../../utils/element-focus';
29+
import { delegateFocus, setFocus } from '../../utils/element-focus';
3030
import { InputColorController } from './controller';
3131

3232
/**
@@ -97,7 +97,7 @@ export class KolInputColor implements InputColorAPI, FocusableElement {
9797
*/
9898
@Method()
9999
public async focus() {
100-
return delegateFocus(this.host!, async () => this.refInputText?.focus?.());
100+
return delegateFocus(this.host!, () => setFocus(this.refInputText!));
101101
}
102102

103103
private get hasSuggestions(): boolean {

packages/components/src/components/input-date/shadow.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import KolFormFieldStateWrapperFc, { type FormFieldStateWrapperProps } from '../
3434
import KolInputContainerFc from '../../functional-component-wrappers/InputContainerStateWrapper/InputContainerStateWrapper';
3535
import KolInputStateWrapperFc, { type InputStateWrapperProps } from '../../functional-component-wrappers/InputStateWrapper/InputStateWrapper';
3636
import { nonce } from '../../utils/dev.utils';
37-
import { delegateFocus } from '../../utils/element-focus';
37+
import { delegateFocus, setFocus } from '../../utils/element-focus';
3838
import { propagateSubmitEventToForm } from '../form/controller';
3939
import { InputDateController } from './controller';
4040

@@ -74,7 +74,7 @@ export class KolInputDate implements InputDateAPI, FocusableElement {
7474
*/
7575
@Method()
7676
public async focus() {
77-
return delegateFocus(this.host!, async () => this.inputRef?.focus?.());
77+
return delegateFocus(this.host!, () => setFocus(this.inputRef!));
7878
}
7979

8080
/**

0 commit comments

Comments
 (0)