Skip to content

Commit

Permalink
fix(progress)!: convert value range to 0-100 (#10622)
Browse files Browse the repository at this point in the history
**Related Issue:** #7207

## Summary
 
Fixes the discrepancy in value range used between Progress (0 -> 1.0)
and Loader (0 -> 100), to have components use a similar expected value.

BREAKING CHANGE: Refactors `progress` to use the value range of 0-100.
Developers will need to provide a function to map existing values or use
the updated range.
  • Loading branch information
Elijbet authored Nov 20, 2024
1 parent 8d1065c commit f7d1d57
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe("calcite-progress", () => {
});

describe("theme", () => {
themed(html`<calcite-progress text="optional text" type="determinate" value="0.5"></calcite-progress>`, {
themed(html`<calcite-progress text="optional text" type="determinate" value="50"></calcite-progress>`, {
"--calcite-progress-background-color": {
shadowSelector: `.${CSS.track}`,
targetProp: "backgroundColor",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default {
title: "Components/Progress",
args: {
type: determinateType.defaultValue,
value: 0.8,
value: 80,
text: "",
},
argTypes: {
Expand All @@ -20,7 +20,7 @@ export default {
control: { type: "select" },
},
value: {
control: { type: "range", min: 0, max: 1, step: 0.01 },
control: { type: "range", min: 0, max: 100, step: 1 },
},
},
};
Expand All @@ -33,7 +33,7 @@ export const darkModeRTL_TestOnly = (): string => html`
<calcite-progress
class="calcite-mode-dark"
type="determinate"
value="0.2"
value="20"
text="% Complete (optional text)"
></calcite-progress>
`;
Expand Down
10 changes: 5 additions & 5 deletions packages/calcite-components/src/components/progress/progress.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class Progress extends LitElement {
*/
@property({ reflect: true }) type: "indeterminate" | "determinate" = "determinate";

/** When `type` is `"determinate"`, the component's progress value with a range of 0.0 - 1.0. */
/** When `type` is `"determinate"`, specifies the component's value with a range of 0 to 100. */
@property() value = 0;

// #endregion
Expand All @@ -43,14 +43,14 @@ export class Progress extends LitElement {

override render(): JsxNode {
const isDeterminate = this.type === "determinate";
const barStyles = isDeterminate ? { width: `${this.value * 100}%` } : {};
const barStyles = isDeterminate ? { width: `${this.value}%` } : {};
const dir = getElementDir(this.el);
return (
<div
ariaLabel={this.label || this.text}
ariaValueMax={1}
ariaValueMin={0}
ariaValueNow={this.value}
ariaValueMax={isDeterminate ? "100" : undefined}
ariaValueMin={isDeterminate ? "0" : undefined}
ariaValueNow={isDeterminate ? this.value : undefined}
role="progressbar"
>
<div class="track">
Expand Down
2 changes: 1 addition & 1 deletion packages/calcite-components/src/custom-theme/progress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ export const progressTokens = {

export const progress = html`
<calcite-label layout="inline">
<calcite-progress text="optional text" type="determinate" value="0.5"></calcite-progress>
<calcite-progress text="optional text" type="determinate" value="50"></calcite-progress>
</calcite-label>
`;

0 comments on commit f7d1d57

Please sign in to comment.