Skip to content

Commit

Permalink
refactor: Ensure all setFocus methods return calls to setFocus (#7287)
Browse files Browse the repository at this point in the history
**Related Issue:** #7270

## Summary

For consistency, components implementing `setFocus` that end up calling
`setFocus` on internal, supporting components should return the promise
from this method call.

- Any component implementing `setFocus` whose method calls `setFocus` or
the `focusElement` helper.
- depends on #7277
  • Loading branch information
driskull authored Jul 7, 2023
1 parent bbe9201 commit 4d60f54
Show file tree
Hide file tree
Showing 10 changed files with 11 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ export class ActionMenu implements LoadableComponent {
async setFocus(): Promise<void> {
await componentFocusable(this);

focusElement(this.menuButtonEl);
return focusElement(this.menuButtonEl);
}

// --------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion packages/calcite-components/src/components/alert/alert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ export class Alert implements OpenCloseComponent, LoadableComponent, T9nComponen
if (!this.closeButton && !alertLinkEl) {
return;
} else if (alertLinkEl) {
alertLinkEl.setFocus();
return alertLinkEl.setFocus();
} else if (this.closeButton) {
this.closeButton.focus();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ export class ChipGroup implements InteractiveComponent {
async setFocus(): Promise<void> {
await componentFocusable(this);
if (!this.disabled) {
(this.selectedItems[0] || this.items[0])?.setFocus();
return (this.selectedItems[0] || this.items[0])?.setFocus();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ export class ColorPickerHexInput implements LoadableComponent {
async setFocus(): Promise<void> {
await componentFocusable(this);

focusElement(this.hexInputNode);
return focusElement(this.hexInputNode);
}

//--------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion packages/calcite-components/src/components/list/list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ export class List implements InteractiveComponent, LoadableComponent {
@Method()
async setFocus(): Promise<void> {
await componentFocusable(this);
this.enabledListItems.find((listItem) => listItem.active)?.setFocus();
return this.enabledListItems.find((listItem) => listItem.active)?.setFocus();
}

// --------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export class CalciteNavigation implements LoadableComponent {
@Method()
async setFocus(): Promise<void> {
await componentFocusable(this);
await this.navigationActionEl?.setFocus();
return this.navigationActionEl?.setFocus();
}

//--------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ export class Notice
return;
}
if (noticeLinkEl) {
noticeLinkEl.setFocus();
return noticeLinkEl.setFocus();
} else if (this.closeButton) {
this.closeButton.focus();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,10 @@ export class RadioButtonGroup implements LoadableComponent {
async setFocus(): Promise<void> {
await componentFocusable(this);
if (this.selectedItem && !this.selectedItem.disabled) {
this.selectedItem.setFocus();
return;
return this.selectedItem.setFocus();
}
if (this.radioButtons.length > 0) {
this.getFocusableRadioButton()?.setFocus();
return this.getFocusableRadioButton()?.setFocus();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export class TileSelect implements InteractiveComponent, LoadableComponent {
async setFocus(): Promise<void> {
await componentFocusable(this);

this.input?.setFocus();
return this.input?.setFocus();
}

//--------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export class ValueListItem
async setFocus(): Promise<void> {
await componentFocusable(this);

this.pickListItem?.setFocus();
return this.pickListItem?.setFocus();
}

// --------------------------------------------------------------------------
Expand Down

0 comments on commit 4d60f54

Please sign in to comment.