From 4d60f54cf2a3cb7c2367b65cbe64fee33a05b600 Mon Sep 17 00:00:00 2001 From: Matt Driscoll Date: Fri, 7 Jul 2023 14:55:12 -0700 Subject: [PATCH] refactor: Ensure all setFocus methods return calls to setFocus (#7287) **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 --- .../src/components/action-menu/action-menu.tsx | 2 +- packages/calcite-components/src/components/alert/alert.tsx | 2 +- .../src/components/chip-group/chip-group.tsx | 2 +- .../color-picker-hex-input/color-picker-hex-input.tsx | 2 +- packages/calcite-components/src/components/list/list.tsx | 2 +- .../src/components/navigation/navigation.tsx | 2 +- packages/calcite-components/src/components/notice/notice.tsx | 2 +- .../src/components/radio-button-group/radio-button-group.tsx | 5 ++--- .../src/components/tile-select/tile-select.tsx | 2 +- .../src/components/value-list-item/value-list-item.tsx | 2 +- 10 files changed, 11 insertions(+), 12 deletions(-) diff --git a/packages/calcite-components/src/components/action-menu/action-menu.tsx b/packages/calcite-components/src/components/action-menu/action-menu.tsx index 9715daa79d0..4c5d92cc49f 100755 --- a/packages/calcite-components/src/components/action-menu/action-menu.tsx +++ b/packages/calcite-components/src/components/action-menu/action-menu.tsx @@ -187,7 +187,7 @@ export class ActionMenu implements LoadableComponent { async setFocus(): Promise { await componentFocusable(this); - focusElement(this.menuButtonEl); + return focusElement(this.menuButtonEl); } // -------------------------------------------------------------------------- diff --git a/packages/calcite-components/src/components/alert/alert.tsx b/packages/calcite-components/src/components/alert/alert.tsx index a59e3bc473f..eabfa9b30a8 100644 --- a/packages/calcite-components/src/components/alert/alert.tsx +++ b/packages/calcite-components/src/components/alert/alert.tsx @@ -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(); } diff --git a/packages/calcite-components/src/components/chip-group/chip-group.tsx b/packages/calcite-components/src/components/chip-group/chip-group.tsx index 39ca1fc0f33..4384741b774 100644 --- a/packages/calcite-components/src/components/chip-group/chip-group.tsx +++ b/packages/calcite-components/src/components/chip-group/chip-group.tsx @@ -184,7 +184,7 @@ export class ChipGroup implements InteractiveComponent { async setFocus(): Promise { await componentFocusable(this); if (!this.disabled) { - (this.selectedItems[0] || this.items[0])?.setFocus(); + return (this.selectedItems[0] || this.items[0])?.setFocus(); } } diff --git a/packages/calcite-components/src/components/color-picker-hex-input/color-picker-hex-input.tsx b/packages/calcite-components/src/components/color-picker-hex-input/color-picker-hex-input.tsx index 53975af63d7..38ac015b64d 100644 --- a/packages/calcite-components/src/components/color-picker-hex-input/color-picker-hex-input.tsx +++ b/packages/calcite-components/src/components/color-picker-hex-input/color-picker-hex-input.tsx @@ -367,7 +367,7 @@ export class ColorPickerHexInput implements LoadableComponent { async setFocus(): Promise { await componentFocusable(this); - focusElement(this.hexInputNode); + return focusElement(this.hexInputNode); } //-------------------------------------------------------------------------- diff --git a/packages/calcite-components/src/components/list/list.tsx b/packages/calcite-components/src/components/list/list.tsx index f092264758f..6ecd00cb8a6 100755 --- a/packages/calcite-components/src/components/list/list.tsx +++ b/packages/calcite-components/src/components/list/list.tsx @@ -269,7 +269,7 @@ export class List implements InteractiveComponent, LoadableComponent { @Method() async setFocus(): Promise { await componentFocusable(this); - this.enabledListItems.find((listItem) => listItem.active)?.setFocus(); + return this.enabledListItems.find((listItem) => listItem.active)?.setFocus(); } // -------------------------------------------------------------------------- diff --git a/packages/calcite-components/src/components/navigation/navigation.tsx b/packages/calcite-components/src/components/navigation/navigation.tsx index f15cb670847..eab2423b3af 100644 --- a/packages/calcite-components/src/components/navigation/navigation.tsx +++ b/packages/calcite-components/src/components/navigation/navigation.tsx @@ -105,7 +105,7 @@ export class CalciteNavigation implements LoadableComponent { @Method() async setFocus(): Promise { await componentFocusable(this); - await this.navigationActionEl?.setFocus(); + return this.navigationActionEl?.setFocus(); } //-------------------------------------------------------------------------- diff --git a/packages/calcite-components/src/components/notice/notice.tsx b/packages/calcite-components/src/components/notice/notice.tsx index c6646de863a..a62c8f7a564 100644 --- a/packages/calcite-components/src/components/notice/notice.tsx +++ b/packages/calcite-components/src/components/notice/notice.tsx @@ -222,7 +222,7 @@ export class Notice return; } if (noticeLinkEl) { - noticeLinkEl.setFocus(); + return noticeLinkEl.setFocus(); } else if (this.closeButton) { this.closeButton.focus(); } diff --git a/packages/calcite-components/src/components/radio-button-group/radio-button-group.tsx b/packages/calcite-components/src/components/radio-button-group/radio-button-group.tsx index 4b301ff37ae..7dc0b078811 100644 --- a/packages/calcite-components/src/components/radio-button-group/radio-button-group.tsx +++ b/packages/calcite-components/src/components/radio-button-group/radio-button-group.tsx @@ -169,11 +169,10 @@ export class RadioButtonGroup implements LoadableComponent { async setFocus(): Promise { 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(); } } diff --git a/packages/calcite-components/src/components/tile-select/tile-select.tsx b/packages/calcite-components/src/components/tile-select/tile-select.tsx index 5674296d6f7..e6aed69b6ad 100644 --- a/packages/calcite-components/src/components/tile-select/tile-select.tsx +++ b/packages/calcite-components/src/components/tile-select/tile-select.tsx @@ -149,7 +149,7 @@ export class TileSelect implements InteractiveComponent, LoadableComponent { async setFocus(): Promise { await componentFocusable(this); - this.input?.setFocus(); + return this.input?.setFocus(); } //-------------------------------------------------------------------------- diff --git a/packages/calcite-components/src/components/value-list-item/value-list-item.tsx b/packages/calcite-components/src/components/value-list-item/value-list-item.tsx index 95b30cc1d46..0a71fc66c34 100644 --- a/packages/calcite-components/src/components/value-list-item/value-list-item.tsx +++ b/packages/calcite-components/src/components/value-list-item/value-list-item.tsx @@ -177,7 +177,7 @@ export class ValueListItem async setFocus(): Promise { await componentFocusable(this); - this.pickListItem?.setFocus(); + return this.pickListItem?.setFocus(); } // --------------------------------------------------------------------------