Skip to content

Commit 18b7a60

Browse files
committed
fix: update focus methods to consistently use setFocus utility across components
1 parent 523eb43 commit 18b7a60

File tree

19 files changed

+42
-37
lines changed

19 files changed

+42
-37
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { nonce } from '../../utils/dev.utils';
88
import type { JSX } from '@stencil/core';
99
import { KolButtonWcTag } from '../../core/component-names';
1010
import clsx from '../../utils/clsx';
11-
import { delegateFocus } from '../../utils/element-focus';
11+
import { delegateFocus, setFocus } from '../../utils/element-focus';
1212
featureHint(`[KolBadge] Optimierung des _color-Properties (rgba, rgb, hex usw.).`);
1313

1414
/**
@@ -58,7 +58,7 @@ export class KolBadge implements BadgeAPI, FocusableElement {
5858
*/
5959
@Method()
6060
public async focus(): Promise<void> {
61-
return delegateFocus(this.host!, () => setFocus(this.smartButtonRef!);
61+
return delegateFocus(this.host!, () => setFocus(this.smartButtonRef!));
6262
}
6363

6464
public render(): JSX.Element {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import type {
1919
TooltipAlignPropType,
2020
VariantClassNamePropType,
2121
} from '../../schema';
22-
import { delegateFocus } from '../../utils/element-focus';
22+
import { delegateFocus, setFocus } from '../../utils/element-focus';
2323

2424
/**
2525
* The **ButtonLink** component is semantically a button but has the appearance of a link. All relevant properties of the Button component are adopted and extended with the design-defining properties of a link.
@@ -63,7 +63,7 @@ export class KolButtonLink implements ButtonLinkProps, FocusableElement {
6363
*/
6464
@Method()
6565
public async focus(): Promise<void> {
66-
return delegateFocus(this.host!, () => setFocus(this.buttonWcRef!);
66+
return delegateFocus(this.host!, () => setFocus(this.buttonWcRef!));
6767
}
6868

6969
public render(): JSX.Element {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import type {
1212
ButtonTypePropType,
1313
CustomClassPropType,
1414
DisabledPropType,
15+
FocusableElement,
1516
HideLabelPropType,
1617
IconsPropType,
1718
IdPropType,
@@ -67,7 +68,7 @@ import { AssociatedInputController } from '../input-adapter-leanup/associated.co
6768
tag: 'kol-button-wc',
6869
shadow: false,
6970
})
70-
export class KolButtonWc implements ButtonAPI {
71+
export class KolButtonWc implements ButtonAPI, FocusableElement {
7172
@Element() private readonly host?: HTMLKolButtonWcElement;
7273
private buttonRef?: HTMLButtonElement;
7374
private tooltipRef?: HTMLKolTooltipWcElement;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import type {
1919
SyncValueBySelectorPropType,
2020
TooltipAlignPropType,
2121
} from '../../schema';
22-
import { delegateFocus } from '../../utils/element-focus';
22+
import { delegateFocus, setFocus } from '../../utils/element-focus';
2323

2424
/**
2525
* The **Button** component is used to present users with action options and arrange them in a clear hierarchy. It helps users find the most important actions on a page or within a viewport and allows them to execute those actions. The button label clearly indicates which action will be triggered. Buttons allow users to confirm a change, complete steps in a task, or make decisions.
@@ -55,7 +55,7 @@ export class KolButton implements ButtonProps, FocusableElement {
5555
*/
5656
@Method()
5757
public async focus(): Promise<void> {
58-
return delegateFocus(this.host!, () => setFocus(this.buttonWcRef!);
58+
return delegateFocus(this.host!, () => setFocus(this.buttonWcRef!));
5959
}
6060

6161
public render(): JSX.Element {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import KolCollapsibleFc, { type CollapsibleProps } from '../../functional-compon
33
import type { DetailsAPI, DetailsCallbacksPropType, DetailsStates, DisabledPropType, FocusableElement, HeadingLevel, LabelPropType } from '../../schema';
44
import { validateDetailsCallbacks, validateDisabled, validateLabel, validateOpen } from '../../schema';
55
import { nonce } from '../../utils/dev.utils';
6-
import { delegateFocus } from '../../utils/element-focus';
6+
import { delegateFocus, setFocus } from '../../utils/element-focus';
77
import { dispatchDomEvent, KolEvent } from '../../utils/events';
88
import { watchHeadingLevel } from '../heading/validation';
99

@@ -40,7 +40,7 @@ export class KolDetails implements DetailsAPI, FocusableElement {
4040
*/
4141
@Method()
4242
public async focus(): Promise<void> {
43-
return delegateFocus(this.host!, () => setFocus(this.buttonWcRef!);
43+
return delegateFocus(this.host!, () => setFocus(this.buttonWcRef!));
4444
}
4545

4646
private toggleTimeout?: ReturnType<typeof setTimeout>;

packages/components/src/components/input-adapter-leanup/associated.controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export class AssociatedInputController implements Watches {
9393
while (host?.shadowRoot === null && host !== document.body) {
9494
host = host?.parentNode as HTMLElement;
9595
if ((host as unknown as ShadowRoot).host) {
96-
host = (host as unknown as ShadowRoot).host;
96+
host = (host as unknown as ShadowRoot).host as HTMLElement;
9797
}
9898
}
9999
return host;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import type {
1919
ShortKeyPropType,
2020
TooltipAlignPropType,
2121
} from '../../schema';
22-
import { delegateFocus } from '../../utils/element-focus';
22+
import { delegateFocus, setFocus } from '../../utils/element-focus';
2323

2424
/**
2525
* The **LinkButton** component is semantically a link but has the appearance of a button. All relevant properties of the Link component are adopted and extended with the design-defining properties of a button.
@@ -46,7 +46,7 @@ export class KolLinkButton implements LinkButtonProps, FocusableElement {
4646
*/
4747
@Method()
4848
public async focus(): Promise<void> {
49-
return delegateFocus(this.host!, () => setFocus(this.linkWcRef!);
49+
return delegateFocus(this.host!, () => setFocus(this.linkWcRef!));
5050
}
5151

5252
public render(): JSX.Element {

packages/components/src/components/link/component.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import type {
1212
CustomClassPropType,
1313
DisabledPropType,
1414
DownloadPropType,
15+
FocusableElement,
1516
HideLabelPropType,
1617
HrefPropType,
1718
InlinePropType,
@@ -52,8 +53,8 @@ import {
5253
validateVariantClassName,
5354
} from '../../schema';
5455
import { validateTabIndex } from '../../schema/props/tab-index';
55-
import { dispatchDomEvent, KolEvent } from '../../utils/events';
5656
import { setFocus } from '../../utils/element-focus';
57+
import { dispatchDomEvent, KolEvent } from '../../utils/events';
5758
import type { UnsubscribeFunction } from './ariaCurrentService';
5859
import { onLocationChange } from './ariaCurrentService';
5960

@@ -69,7 +70,7 @@ import clsx from '../../utils/clsx';
6970
tag: 'kol-link-wc',
7071
shadow: false,
7172
})
72-
export class KolLinkWc implements InternalLinkAPI {
73+
export class KolLinkWc implements InternalLinkAPI, FocusableElement {
7374
@Element() private readonly host?: HTMLKolLinkElement;
7475

7576
private anchorRef?: HTMLAnchorElement;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import type {
2020
TooltipAlignPropType,
2121
VariantClassNamePropType,
2222
} from '../../schema';
23-
import { delegateFocus } from '../../utils/element-focus';
23+
import { delegateFocus, setFocus } from '../../utils/element-focus';
2424

2525
@Component({
2626
tag: 'kol-link',
@@ -42,7 +42,7 @@ export class KolLink implements LinkProps, FocusableElement {
4242
*/
4343
@Method()
4444
public async focus(): Promise<void> {
45-
return delegateFocus(this.host!, () => setFocus(this.linkWcRef!);
45+
return delegateFocus(this.host!, () => setFocus(this.linkWcRef!));
4646
}
4747

4848
public render(): JSX.Element {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import type {
1010
ButtonTypePropType,
1111
ButtonVariantPropType,
1212
CustomClassPropType,
13+
FocusableElement,
1314
IconsPropType,
1415
IdPropType,
1516
InlinePropType,
@@ -38,7 +39,7 @@ import { setFocus } from '../../utils/element-focus';
3839
shadow: false,
3940
})
4041
// class implementing PopoverButtonProps and not API because we don't want to repeat the entire state and validation for button props
41-
export class KolPopoverButtonWc implements PopoverButtonProps {
42+
export class KolPopoverButtonWc implements PopoverButtonProps, FocusableElement {
4243
private refButton?: HTMLKolButtonWcElement;
4344
private readonly popoverCtrl = new PopoverController();
4445
private popoverElement?: HTMLDivElement;

0 commit comments

Comments
 (0)