Skip to content

Commit

Permalink
refactor progress bar to use ElementInternals
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisdholt committed Jun 11, 2024
1 parent 71dc8a7 commit 8e9d16f
Show file tree
Hide file tree
Showing 11 changed files with 191 additions and 296 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "refactor progress bar to use ElementInternals",
"packageName": "@fluentui/web-components",
"email": "[email protected]",
"dependentChangeType": "patch"
}
28 changes: 18 additions & 10 deletions packages/web-components/docs/api-report.md
Original file line number Diff line number Diff line change
Expand Up @@ -1888,7 +1888,6 @@ export function display(displayValue: CSSDisplayPropertyValue): string;
//
// @public
export class Divider extends FASTElement {
constructor();
// (undocumented)
alignContent?: DividerAlignContent;
// (undocumented)
Expand Down Expand Up @@ -2437,13 +2436,28 @@ export const MenuStyles: ElementStyles;
// @public (undocumented)
export const MenuTemplate: ElementViewTemplate<Menu>;

// Warning: (ae-forgotten-export) The symbol "BaseProgress" needs to be exported by the entry point index.d.ts
//
// @public
export class ProgressBar extends BaseProgress {
export class ProgressBar extends FASTElement {
// @internal
constructor();
// @internal (undocumented)
connectedCallback(): void;
// @internal
elementInternals: ElementInternals;
max?: number;
// (undocumented)
protected maxChanged(): void;
min?: number;
// (undocumented)
protected minChanged(): void;
// @internal
percentComplete: number;
shape?: ProgressBarShape;
thickness?: ProgressBarThickness;
validationState: ProgressBarValidationState | null;
value?: number | null;
// (undocumented)
protected valueChanged(): void;
}

// @public
Expand Down Expand Up @@ -2485,12 +2499,6 @@ export const ProgressBarValidationState: {
// @public
export type ProgressBarValidationState = ValuesOf<typeof ProgressBarValidationState>;

// @public
export type ProgressOptions = {
indeterminateIndicator1?: StaticallyComposableHTML<ProgressBar>;
indeterminateIndicator2?: StaticallyComposableHTML<ProgressBar>;
};

// Warning: (ae-forgotten-export) The symbol "FormAssociatedRadio" needs to be exported by the entry point index.d.ts
//
// @public
Expand Down
1 change: 0 additions & 1 deletion packages/web-components/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ export {
ProgressBarThickness,
ProgressBarValidationState,
} from './progress-bar/index.js';
export type { ProgressOptions } from './progress-bar/index.js';
export {
RadioGroup,
RadioGroupDefinition,
Expand Down
71 changes: 0 additions & 71 deletions packages/web-components/src/progress-bar/base-progress.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/web-components/src/progress-bar/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export { definition as ProgressBarDefinition } from './progress-bar.definition.js';
export { ProgressBar } from './progress-bar.js';
export { ProgressBarShape, ProgressBarThickness, ProgressBarValidationState } from './progress-bar.options.js';
export type { ProgressOptions } from './progress-bar.options.js';
export { styles as ProgressBarStyles } from './progress-bar.styles.js';
export { template as ProgressBarTemplate } from './progress-bar.template.js';
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,3 @@ export const ProgressBarValidationState = {
* @public
*/
export type ProgressBarValidationState = ValuesOf<typeof ProgressBarValidationState>;

/**
* Progress configuration options
* @public
*/
export type ProgressOptions = {
indeterminateIndicator1?: StaticallyComposableHTML<ProgressBar>;
indeterminateIndicator2?: StaticallyComposableHTML<ProgressBar>;
};
32 changes: 4 additions & 28 deletions packages/web-components/src/progress-bar/progress-bar.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ test.describe('Progress Bar', () => {

// Foundation tests
test('should include a role of progressbar', async () => {
await expect(element).toHaveAttribute('role', 'progressbar');
await expect(element).toHaveJSProperty('elementInternals.role', 'progressbar');
});

test('should set the `aria-valuenow` attribute with the `value` property when provided', async () => {
Expand All @@ -34,7 +34,7 @@ test.describe('Progress Bar', () => {
`;
});

await expect(element).toHaveAttribute('aria-valuenow', '50');
await expect(element).toHaveJSProperty('elementInternals.ariaValueNow', '50');
});

test('should set the `aria-valuemin` attribute with the `min` property when provided', async () => {
Expand All @@ -44,7 +44,7 @@ test.describe('Progress Bar', () => {
`;
});

await expect(element).toHaveAttribute('aria-valuemin', '50');
await expect(element).toHaveJSProperty('ariaValueMin', '50');
});

test('should set the `aria-valuemax` attribute with the `max` property when provided', async () => {
Expand All @@ -54,31 +54,7 @@ test.describe('Progress Bar', () => {
`;
});

await expect(element).toHaveAttribute('aria-valuemax', '50');
});

test('should render an element with a `determinate` slot when a value is provided', async () => {
await root.evaluate(node => {
node.innerHTML = /* html */ `
<fluent-progress-bar value="50"></fluent-progress-bar>
`;
});

const progress = element.locator('.progress');

await expect(progress).toHaveAttribute('slot', 'determinate');
});

test('should render an element with an `indeterminate` slot when no value is provided', async () => {
await root.evaluate(node => {
node.innerHTML = /* html */ `
<fluent-progress-bar></fluent-progress-bar>
`;
});

const progress = element.locator('.progress');

await expect(progress).toHaveAttribute('slot', 'indeterminate');
await expect(element).toHaveJSProperty('ariaValueMax', '50');
});

test('should return the `percentComplete` property as a value between 0 and 100 when `min` and `max` are unset', async () => {
Expand Down
17 changes: 8 additions & 9 deletions packages/web-components/src/progress-bar/progress-bar.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ const storyTemplate = html<ProgressStoryArgs>`
thickness=${x => x.thickness}
shape=${x => x.shape}
max=${x => x.max}
aria-valuemax=${x => x.max}
aria-valuenow=${x => x.value}
min=${x => x.min}
value=${x => x.value}
validation-state=${x => x.validationState}
></fluent-progress-bar>
Expand Down Expand Up @@ -72,26 +71,26 @@ export const Max = renderComponent(html<ProgressStoryArgs>`
<div>
<p>
<code>3 of 10</code>
<fluent-progress-bar value="3" aria-valuenow="3" max="10" aria-valuemax="10"></fluent-progress-bar>
<fluent-progress-bar value="3" max="10"></fluent-progress-bar>
</p>
<p>
<code>3 o 5</code>
<fluent-progress-bar value="3" aria-valuenow="3" max="5" aria-valuemax="5"></fluent-progress-bar>
<fluent-progress-bar value="3" max="5"></fluent-progress-bar>
</p>
</div>
`);

export const Value = renderComponent(html<ProgressStoryArgs>`
<div>
<code>0</code><fluent-progress-bar value="0" aria-valuenow="0"></fluent-progress-bar>
<code>0</code><fluent-progress-bar value="0"></fluent-progress-bar>
<code>25</code>
<fluent-progress-bar value="25" aria-valuenow="25"></fluent-progress-bar>
<fluent-progress-bar value="25"></fluent-progress-bar>
<code>50</code>
<fluent-progress-bar value="50" aria-valuenow="50"></fluent-progress-bar>
<fluent-progress-bar value="50"></fluent-progress-bar>
<code>75</code>
<fluent-progress-bar value="75" aria-valuenow="75"></fluent-progress-bar>
<fluent-progress-bar value="75"></fluent-progress-bar>
<code>100</code>
<fluent-progress-bar value="100" aria-valuenow="100"></fluent-progress-bar>
<fluent-progress-bar value="100"></fluent-progress-bar>
</div>
`);

Expand Down
Loading

0 comments on commit 8e9d16f

Please sign in to comment.