Skip to content

Add focus option to selectTab method#119

Open
medmunds wants to merge 1 commit into
github:mainfrom
medmunds:117-selecttab-focus-option
Open

Add focus option to selectTab method#119
medmunds wants to merge 1 commit into
github:mainfrom
medmunds:117-selecttab-focus-option

Conversation

@medmunds

Copy link
Copy Markdown

Add focus option to selectTab() method. By default, sets focus to newly selected tab as in existing behavior. With {focus: false} does not change focus.

Fixes #117.

Allow an optional, second `options` argument to `selectTab()`.

Add support for a `focus` option which controls whether the newly selected tab
is given focus. The default is true, matching previous behavior without the option.

Document the `selectTab()` method in the readme.
@medmunds
medmunds requested a review from a team as a code owner July 17, 2026 02:22
Comment on lines 297 to 299
set selectedTabIndex(i: number) {
this.selectTab(i)
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As requested I have not changed any existing functionality. However, I might suggest changing this (undocumented, untested) selectedTabIndex setter to not change focus. As a custom component user, I would find it surprising that setting someTabContainer.selectedTabIndex = 3 would have a side effect of moving focus. (Just my opinion.)

  set selectedTabIndex(i: number) {
-   this.selectTab(i)
+   this.selectTab(i, {focus: false})
  }

@francinelucca francinelucca left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good! let's keep the selectedTabIndex setter behavior as-is. I fear changing it would constitute major-breaking behavior.

@medmunds

Copy link
Copy Markdown
Author

Incidentally, the generated custom-elements.json is out of sync with the checked-in version (before this PR). It also seems to be wrong: the CEM refers to generated code in files like dist/bundle.js (see below).

The CEM isn't included in the npm package, so I just ignored it for this PR. (Let me know if I should open an issue or just continue ignoring it.)

To see what I mean, in a fresh clone of the repo:

# Install *exactly* package-lock.json:
npm ci
npm build
git diff

Results:

diff --git a/custom-elements.json b/custom-elements.json
index 5772e8e..8e6e938 100644
--- a/custom-elements.json
+++ b/custom-elements.json
@@ -9,16 +9,16 @@
         {
           "kind": "variable",
           "name": "TabContainerChangeEvent",
-          "default": "_TabContainerChangeEvent"
+          "default": "class extends Event {\n  static"
         },
         {
           "kind": "variable",
           "name": "TabContainerElement",
-          "default": "_TabContainerElement"
+          "default": "class extends HTMLElement {\n  static"
         },
         {
           "kind": "variable",
-          "name": "dist_default",
+          "name": "index_default",
           "default": "TabContainerElement"
         }
       ],
@@ -43,7 +43,7 @@
           "kind": "js",
           "name": "default",
           "declaration": {
-            "name": "dist_default",
+            "name": "index_default",
             "module": "dist/bundle.js"
           }
         }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

selectTab() without changing focus?

2 participants