Skip to content

Commit

Permalink
refactor(chip)!: make label property required and value optional (#10787
Browse files Browse the repository at this point in the history
)

**Related Issue:** #8696

## Summary

- Make the `label` property required to ensure it is provided to a11y
assistive technologies.
- Make the `value` property optional in favor of `label`.

BREAKING CHANGE: The `label` property is now required and `value` is
optional.
  • Loading branch information
benelan authored Nov 23, 2024
1 parent c2f12cf commit 31f0fe4
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/calcite-components/src/components/alert/alert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ export class Alert extends LitElement implements OpenCloseComponent, LoadableCom
}}
key="queue-count"
>
<calcite-chip scale={this.scale} value={queueText}>
<calcite-chip label={queueText} scale={this.scale} value={queueText}>
{queueText}
</calcite-chip>
</div>
Expand Down
12 changes: 6 additions & 6 deletions packages/calcite-components/src/components/chip/chip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ export class Chip extends LitElement implements InteractiveComponent, LoadableCo
/** Specifies the kind of the component, which will apply to border and background if applicable. */
@property({ reflect: true }) kind: Extract<"brand" | "inverse" | "neutral", Kind> = "neutral";

/** Accessible name for the component. */
/**
* Accessible name for the component.
*
* @required
*/
@property() label: string;

/** Use this property to override individual strings used by the component. */
Expand Down Expand Up @@ -124,11 +128,7 @@ export class Chip extends LitElement implements InteractiveComponent, LoadableCo
SelectionMode
> = "none";

/**
* The component's value.
*
* @required
*/
/** The component's value. */
@property() value: any;

// #endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1447,6 +1447,7 @@ export class Combobox
iconFlipRtl={item.iconFlipRtl}
id={item.guid ? `${chipUidPrefix}${item.guid}` : null}
key={itemLabel}
label={label}
messageOverrides={{ dismissLabel: messages.removeTag }}
onFocusIn={() => (this.activeChipIndex = i)}
oncalciteChipClose={() => this.calciteChipCloseHandler(item)}
Expand Down Expand Up @@ -1480,6 +1481,7 @@ export class Combobox
!compactSelectionDisplay
),
}}
label={label}
ref={setAllSelectedIndicatorChipEl}
scale={scale}
title={label}
Expand All @@ -1503,6 +1505,7 @@ export class Combobox
compactSelectionDisplay
),
}}
label={label}
scale={scale}
title={label}
value=""
Expand Down Expand Up @@ -1555,6 +1558,7 @@ export class Combobox
chip: true,
[CSS.chipInvisible]: chipInvisible,
}}
label={label}
ref={setSelectedIndicatorChipEl}
scale={scale}
title={label}
Expand Down Expand Up @@ -1596,6 +1600,7 @@ export class Combobox
chip: true,
[CSS.chipInvisible]: chipInvisible,
}}
label={label}
scale={scale}
title={label}
value=""
Expand Down
6 changes: 4 additions & 2 deletions packages/calcite-components/src/components/rating/rating.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,8 @@ export class Rating
// #region Rendering

override render(): JsxNode {
const countString = this.count?.toString();

return (
<InteractiveContainer disabled={this.disabled}>
<span class="wrapper">
Expand Down Expand Up @@ -442,9 +444,9 @@ export class Rating
)}

{(this.count || this.average) && this.showChip ? (
<calcite-chip scale={this.scale} value={this.count?.toString()}>
<calcite-chip label={countString} scale={this.scale} value={countString}>
{!!this.average && <span class="number--average">{this.average.toString()}</span>}
{!!this.count && <span class="number--count">({this.count?.toString()})</span>}
{!!this.count && <span class="number--count">({countString})</span>}
</calcite-chip>
) : null}
</fieldset>
Expand Down
9 changes: 8 additions & 1 deletion packages/calcite-components/src/components/table/table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -401,13 +401,20 @@ export class Table extends LitElement implements LoadableComponent {
<div class={CSS.selectionArea}>
<calcite-chip
kind={this.selectedCount > 0 ? "brand" : "neutral"}
label={selectionText}
scale={this.scale}
value={selectionText}
>
{selectionText}
</calcite-chip>
{outOfViewCount > 0 && (
<calcite-chip icon="hide-empty" scale={this.scale} title={outOfView} value={outOfView}>
<calcite-chip
icon="hide-empty"
label={outOfView}
scale={this.scale}
title={outOfView}
value={outOfView}
>
{localizedOutOfView}
</calcite-chip>
)}
Expand Down

0 comments on commit 31f0fe4

Please sign in to comment.