Skip to content

Commit fbd3971

Browse files
committed
feat(cards): conformance and consistency
1 parent 8b9f61d commit fbd3971

2 files changed

Lines changed: 17 additions & 9 deletions

File tree

2nd-gen/packages/core/components/card/Card.base.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@ import {
2828
* Abstract base class for all card-family components. Owns the semantics
2929
* shared across every card type: sizing, visual variant, and density.
3030
*
31-
* `swc-card`, `swc-asset-card`, `swc-user-card`, and `swc-product-card` each
32-
* extend this base directly and render the shared anatomy via
33-
* `renderCardTemplate()` in `swc/components/card/card-template.ts`. That
34-
* template also carries a collection placeholder and an avatar/thumbnail
35-
* glyph, each supplied per-component via `renderCollection`/`renderGlyph`.
31+
* `swc-card`, `swc-user-card`, and `swc-product-card` each extend this base
32+
* directly and render the shared anatomy via `renderCardTemplate()` in
33+
* `swc/components/card/card-template.ts`. That template also carries a
34+
* collection placeholder and an avatar/thumbnail glyph, each supplied
35+
* per-component via `renderCollection`/`renderGlyph`.
36+
*
37+
* @attribute {ElementSize} size - The size of the card.
3638
*
3739
* @slot preview - Primary preview content
3840
* @slot title - Card title
@@ -226,7 +228,13 @@ export abstract class CardBase extends SizedMixin(SpectrumElement, {
226228
return node instanceof HTMLElement && node.tabIndex >= 0;
227229
}
228230

229-
private readonly handleSurfaceClick = (event: Event): void => {
231+
/**
232+
* Proxies a qualifying surface click to `titleAsLink`'s link and/or
233+
* dispatches `swc-card-click` for `selectable`, after filtering out
234+
* clicks that landed on a nested interactive target (see `isFocusable()`
235+
* and the `actions`-slot exclusion above).
236+
*/
237+
protected readonly handleSurfaceClick = (event: Event): void => {
230238
if (!this.titleAsLink && !this.selectable) {
231239
return;
232240
}
@@ -262,7 +270,7 @@ export abstract class CardBase extends SizedMixin(SpectrumElement, {
262270
* `selectable` makes the card itself the focused target, regardless of
263271
* what that activation happens to proxy to.
264272
*/
265-
private readonly handleSelectableKeydown = (event: KeyboardEvent): void => {
273+
protected readonly handleSelectableKeydown = (event: KeyboardEvent): void => {
266274
if (event.code === 'Enter' || event.code === 'Space') {
267275
event.preventDefault();
268276
this.handleSurfaceClick(event);

2nd-gen/packages/swc/components/card/card-template.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { html, nothing, TemplateResult } from 'lit';
1616
* Options for {@link renderCardTemplate}.
1717
*/
1818
export interface CardTemplateOptions {
19-
/** Per-component class root (e.g. `AssetCard`), prefixed with `swc-`. */
19+
/** Per-component class root (e.g. `UserCard`), prefixed with `swc-`. */
2020
cardClass: string;
2121

2222
/** Renders the collection slot in addition to the preview. Default: none. */
@@ -30,7 +30,7 @@ export interface CardTemplateOptions {
3030
* Shared card anatomy: preview with an optional collection slot, an
3131
* optional avatar/thumbnail glyph, title/actions/description/default
3232
* content, and a footer. Called from each concrete card's `render()`
33-
* (swc-card, swc-asset-card, swc-user-card, swc-product-card).
33+
* (swc-card, swc-user-card, swc-product-card).
3434
*/
3535
export function renderCardTemplate({
3636
cardClass,

0 commit comments

Comments
 (0)