-
Notifications
You must be signed in to change notification settings - Fork 254
feat(infield-button): Phase 2 — file structure, API, TypeScript, and accessibility #6492
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Rajdeepc
merged 2 commits into
main
from
rajdeepc/feat-infield-button-migration-phase-2
Jul 13, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
2nd-gen/packages/core/components/infield-button/InfieldButton.base.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| /** | ||
| * Copyright 2026 Adobe. All rights reserved. | ||
| * This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. You may obtain a copy | ||
| * of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software distributed under | ||
| * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
| * OF ANY KIND, either express or implied. See the License for the specific language | ||
| * governing permissions and limitations under the License. | ||
| */ | ||
|
|
||
| import { property } from 'lit/decorators.js'; | ||
|
|
||
| import { ButtonBase } from '@spectrum-web-components/core/components/button'; | ||
| import { SpectrumElement } from '@spectrum-web-components/core/element/index.js'; | ||
|
|
||
| import { | ||
| INFIELD_BUTTON_VALID_SIZES, | ||
| type InfieldButtonSize, | ||
| } from './InfieldButton.types.js'; | ||
|
|
||
| /** | ||
| * Abstract base class for infield button components. Extends ButtonBase with a | ||
| * restricted size set, quiet treatment, and non-focusable shadow root. | ||
| * | ||
| * Infield buttons are always embedded inside a form field (e.g. number field). They are | ||
| * clickable via pointer only; they are not in the tab order and not independently focusable. | ||
| * All keyboard behavior is owned by the parent field, which also provides the visible | ||
| * focus ring. The parent field is expected to set the `size` attribute. | ||
| * | ||
| * @slot icon - Icon to display inside the button. | ||
| * | ||
| * @attribute {ElementSize} size - Size delegated from the parent field. Defaults to | ||
| * medium when no parent sets it, though standalone usage is not supported. | ||
| */ | ||
| export abstract class InfieldButtonBase extends ButtonBase { | ||
| // ──────────────────── | ||
| // API OVERRIDES | ||
| // ──────────────────── | ||
|
|
||
| /** @internal */ | ||
| static override readonly VALID_SIZES: readonly InfieldButtonSize[] = | ||
| INFIELD_BUTTON_VALID_SIZES; | ||
|
|
||
| // Infield buttons are clickable but never independently focusable. The parent field | ||
| // owns keyboard behavior and supplies the only focus ring. | ||
| static override shadowRootOptions: ShadowRootInit = { | ||
| ...SpectrumElement.shadowRootOptions, | ||
| delegatesFocus: false, | ||
| }; | ||
|
|
||
| // ─────────────────── | ||
| // API ADDITIONS | ||
| // ─────────────────── | ||
|
|
||
| /** | ||
| * Applies the quiet (no-border) visual treatment. Used when the infield button | ||
| * is part of a quiet field variant. | ||
| */ | ||
| @property({ type: Boolean, reflect: true }) | ||
| public quiet: boolean = false; | ||
| } |
30 changes: 30 additions & 0 deletions
30
2nd-gen/packages/core/components/infield-button/InfieldButton.types.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| /** | ||
| * Copyright 2026 Adobe. All rights reserved. | ||
| * This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. You may obtain a copy | ||
| * of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software distributed under | ||
| * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
| * OF ANY KIND, either express or implied. See the License for the specific language | ||
| * governing permissions and limitations under the License. | ||
| */ | ||
|
|
||
| import type { ElementSize } from '@spectrum-web-components/core/mixins/index.js'; | ||
|
|
||
| // ────────────────── | ||
| // SHARED | ||
| // ────────────────── | ||
|
|
||
| export const INFIELD_BUTTON_VALID_SIZES = [ | ||
| 's', | ||
| 'm', | ||
| 'l', | ||
| 'xl', | ||
| ] as const satisfies readonly ElementSize[]; | ||
|
|
||
| // ────────────────── | ||
| // TYPES | ||
| // ────────────────── | ||
|
|
||
| export type InfieldButtonSize = (typeof INFIELD_BUTTON_VALID_SIZES)[number]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| /** | ||
| * Copyright 2026 Adobe. All rights reserved. | ||
| * This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. You may obtain a copy | ||
| * of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software distributed under | ||
| * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
| * OF ANY KIND, either express or implied. See the License for the specific language | ||
| * governing permissions and limitations under the License. | ||
| */ | ||
| export * from './InfieldButton.base.js'; | ||
| export * from './InfieldButton.types.js'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
2nd-gen/packages/swc/components/infield-button/InfieldButton.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| /** | ||
| * Copyright 2026 Adobe. All rights reserved. | ||
| * This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. You may obtain a copy | ||
| * of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software distributed under | ||
| * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
| * OF ANY KIND, either express or implied. See the License for the specific language | ||
| * governing permissions and limitations under the License. | ||
| */ | ||
|
|
||
| import { CSSResultArray, html, TemplateResult } from 'lit'; | ||
| import { classMap } from 'lit/directives/class-map.js'; | ||
| import { ifDefined } from 'lit/directives/if-defined.js'; | ||
|
|
||
| import { | ||
| INFIELD_BUTTON_VALID_SIZES, | ||
| InfieldButtonBase, | ||
| type InfieldButtonSize, | ||
| } from '@spectrum-web-components/core/components/infield-button'; | ||
|
|
||
| import styles from './infield-button.css'; | ||
|
|
||
| /** | ||
| * A compact icon button embedded inside a form field (e.g. number field increment/decrement | ||
| * control, search field clear button). Clickable via pointer only; not in the tab order. | ||
| * The parent field owns all keyboard behavior and provides the visible focus ring. | ||
| * | ||
| * @element swc-infield-button | ||
| * @since 2.0.0 | ||
| * | ||
| * @slot icon - Icon to display inside the button. | ||
| * | ||
| * @example | ||
| * <swc-infield-button accessible-label="Increment value" size="m"> | ||
| * <sp-icon-chevron100 slot="icon"></sp-icon-chevron100> | ||
| * </swc-infield-button> | ||
| */ | ||
| export class InfieldButton extends InfieldButtonBase { | ||
| // ──────────────────── | ||
| // API OVERRIDES | ||
| // ──────────────────── | ||
|
|
||
| /** @internal */ | ||
| static override readonly VALID_SIZES: readonly InfieldButtonSize[] = | ||
| INFIELD_BUTTON_VALID_SIZES; | ||
|
|
||
| // ────────────────────────────── | ||
| // RENDERING & STYLING | ||
| // ────────────────────────────── | ||
|
|
||
| public static override get styles(): CSSResultArray { | ||
| return [styles]; | ||
| } | ||
|
|
||
| protected override render(): TemplateResult { | ||
| return html` | ||
| <button | ||
| class=${classMap({ 'swc-InfieldButton': true })} | ||
| type="button" | ||
| tabindex="-1" | ||
| @click=${this.handleClick} | ||
| ?disabled=${this.disabled} | ||
| aria-label=${ifDefined(this.accessibleLabel)} | ||
| > | ||
| <slot name="icon"></slot> | ||
| </button> | ||
| `; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| /** | ||
| * Copyright 2026 Adobe. All rights reserved. | ||
| * This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. You may obtain a copy | ||
| * of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software distributed under | ||
| * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
| * OF ANY KIND, either express or implied. See the License for the specific language | ||
| * governing permissions and limitations under the License. | ||
| */ | ||
| export * from './InfieldButton.js'; |
16 changes: 16 additions & 0 deletions
16
2nd-gen/packages/swc/components/infield-button/infield-button.css
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| /* | ||
| * Copyright 2026 Adobe. All rights reserved. | ||
| * This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. You may obtain a copy | ||
| * of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software distributed under | ||
| * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
| * OF ANY KIND, either express or implied. See the License for the specific language | ||
| * governing permissions and limitations under the License. | ||
| */ | ||
|
|
||
| /* Placeholder — full styles authored in Phase 5 */ | ||
| :host { | ||
| display: inline-flex; | ||
| } |
22 changes: 22 additions & 0 deletions
22
2nd-gen/packages/swc/components/infield-button/swc-infield-button.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| /** | ||
| * Copyright 2026 Adobe. All rights reserved. | ||
| * This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. You may obtain a copy | ||
| * of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software distributed under | ||
| * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
| * OF ANY KIND, either express or implied. See the License for the specific language | ||
| * governing permissions and limitations under the License. | ||
| */ | ||
| import { defineElement } from '@spectrum-web-components/core/element/index.js'; | ||
|
|
||
| import { InfieldButton } from './InfieldButton.js'; | ||
|
|
||
| declare global { | ||
| interface HTMLElementTagNameMap { | ||
| 'swc-infield-button': InfieldButton; | ||
| } | ||
| } | ||
|
|
||
| defineElement('swc-infield-button', InfieldButton); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this to be named, or can it be a default slot?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it needs to stay named.
ButtonBasecomposesObserveSlotPresence(SpectrumElement, '[slot="icon"]'), sohasIcon(i.e.this.slotContentIsPresent) only fires when content is assigned to the named slot. You are right a default-slot icon would make it permanentlyfalse, which in turn would silence the dev-modeaccessible-labelwarning inButtonBase.update()that guards against unlabelled icon buttons.I am keeping it named also stays consistent with every other
ButtonBasesubclass and matches the 1st-gen consumer API, so there's one less migration burden either way.