Skip to content

refactor(core): lean out SpectrumElement#6523

Open
caseyisonit wants to merge 1 commit into
mainfrom
caseyisonit/spectrum-element-cleanup-b04490
Open

refactor(core): lean out SpectrumElement#6523
caseyisonit wants to merge 1 commit into
mainfrom
caseyisonit/spectrum-element-cleanup-b04490

Conversation

@caseyisonit

Copy link
Copy Markdown
Contributor

Description

Trims SpectrumElement (2nd-gen @adobe/spectrum-wc-core) down to only what every component actually needs, and moves an unused helper out to a utility.

  • Extract hasVisibleFocusInTreeisFocusVisibleInTree(root) util. It has zero 2nd-gen component callers and is a one-liner over the existing getActiveElement util. Now exported from @adobe/spectrum-wc-core/utils with a unit test. This follows the project rule that a helper used by two or fewer components belongs in utils.
  • Remove the get dir() override. It returned the computed direction and was load-bearing in 1st-gen, but 2nd-gen deliberately resolves direction via getComputedStyle(...).direction at each call site (Tabs, Tooltip, focusgroup-navigation and placement controllers). No 2nd-gen component, controller, test, or Storybook addon reads element.dir.
  • Remove SpectrumMixin / SpectrumInterface. Once the focus helper moved out, the mixin's only remaining job was re-typing shadowRoot as non-null, which nothing relied on (every read already uses ?.). It was applied exactly once, to LitElement, by SpectrumElement itself. SpectrumElement now extends LitElement directly and shadowRoot reverts to ShadowRoot | null.
  • Storybook: drop the stale dir / hasVisibleFocusInTree entries from the argTypes hide-list.

Why this is low risk

  • No internal consumers of anything removed. Repo-wide search: hasVisibleFocusInTree had 0 2nd-gen callers; .dir had 0 JS reads in 2nd-gen source; SpectrumMixin/SpectrumInterface were imported by no component and re-exported nowhere; no code reads this.shadowRoot without optional chaining.
  • The extracted util is a behavior-preserving copy of the removed method body, plus a focused unit test.
  • get dir() removal aligns with existing 2nd-gen convention, which already prefers per-site getComputedStyle(...).direction (with an in-code comment justifying not walking dir).
  • The only breaking surface is the removal of the SpectrumMixin / SpectrumInterface exports from @adobe/spectrum-wc-core. No known external consumer uses them; cheap to remove pre-1.0 (0.3.0) and captured in the changeset as a minor bump.

Motivation and context

SpectrumElement is the root of 34 2nd-gen component bases. Keeping it minimal reduces surface area, removes 1st-gen carryovers that 2nd-gen has already replaced, and keeps shared helpers where the project conventions expect them.

Related issue(s)

Author's checklist

  • I have read the CONTRIBUTING and PULL_REQUESTS documents.
  • I have reviewed the Accessibility Practices for this feature.
  • I have added automated tests to cover my changes.
  • I have included a well-written changeset if my change needs to be published.
  • I have included updated documentation if my change required it.

Manual review test cases

  • Build and lint pass

    1. From repo root, run yarn build
    2. Run yarn lint
    3. Expect both to succeed with no reference to removed members
  • Focus utility behaves as before

    1. Run the core utils test suite
    2. Exercise isFocusVisibleInTree
    3. Expect false when nothing is focused, and a value matching :focus-visible for the active element
  • Storybook renders cleanly

    1. Start Storybook
    2. Open any component's Docs/API table
    3. Expect no dir or hasVisibleFocusInTree rows and no console errors

Device review

  • Did it pass in Desktop?
  • Did it pass in (emulated) Mobile?
  • Did it pass in (emulated) iPad?

Accessibility testing checklist

  • Keyboard

    1. Open any interactive component story (e.g. Button, Tabs)
    2. Tab through and operate it with the keyboard
    3. Expect focus order, focus ring visibility, and activation to be unchanged from main
  • Screen reader

    1. Open the same stories with VoiceOver (or NVDA)
    2. Navigate the components
    3. Expect roles, names, and state announcements to be unchanged from main

Trim SpectrumElement to only what every 2nd-gen component needs:

- Extract `hasVisibleFocusInTree` into the `isFocusVisibleInTree(root)` utility
  (mirrors the existing `getActiveElement` util it wraps); add a unit test and
  export from `@adobe/spectrum-wc-core/utils`. No 2nd-gen component consumed the
  method.
- Remove the `get dir()` override. 2nd-gen resolves direction via
  `getComputedStyle(...).direction` at each call site; nothing read `element.dir`.
- Remove the now-empty `SpectrumMixin` / `SpectrumInterface`. Their only remaining
  job was a non-null `shadowRoot` retype nothing relied on (all reads use `?.`).
  `SpectrumElement` now extends `LitElement` directly.
- Drop the stale `hasVisibleFocusInTree` / `dir` entries from the Storybook
  argTypes hide-list.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@caseyisonit
caseyisonit requested a review from a team as a code owner July 16, 2026 23:16
@changeset-bot

changeset-bot Bot commented Jul 16, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 057ec04

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@adobe/spectrum-wc-core Minor
@adobe/spectrum-wc Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@caseyisonit caseyisonit added the Status:Ready for review PR ready for review or re-review. label Jul 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Status:Ready for review PR ready for review or re-review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant