Merge branch 'test/progress' of https://github.com/christoshrousis/shoelace into christoshrousis-test/progress

pull/568/head
Cory LaViska 2021-10-14 08:10:57 -04:00
commit 45ceff4c08
5 zmienionych plików z 186 dodań i 3 usunięć

Wyświetl plik

@ -20,10 +20,10 @@ Use the `--size` custom property to set the diameter of the progress ring.
### Track Width
Use the `track-width` attribute to set the width of the progress ring's track.
Use the `--track-width` custom property to set the width of the progress ring's track.
```html preview
<sl-progress-ring value="50" stroke-width="10"></sl-progress-ring>
<sl-progress-ring value="50" style="--track-width: 10px;"></sl-progress-ring>
```
### Colors

Wyświetl plik

@ -0,0 +1,89 @@
import { expect, fixture, html } from '@open-wc/testing';
import '../../../dist/shoelace.js';
import type SlProgressBar from './progress-bar';
describe('<sl-progress-bar>', () => {
let el: SlProgressBar;
describe('when provided just a value parameter', async () => {
before(async () => {
el = await fixture<SlProgressBar>(html`<sl-progress-bar value="25"></sl-progress-bar>`);
});
it('should render a component that does not pass accessibility test.', async () => {
await expect(el).not.to.be.accessible();
});
});
describe('when provided a title, and value parameter', async () => {
let base: HTMLDivElement;
let indicator: HTMLDivElement;
before(async () => {
el = await fixture<SlProgressBar>(
html`<sl-progress-bar title="Titled Progress Ring" value="25"></sl-progress-bar>`
);
base = el.shadowRoot?.querySelector('[part="base"]') as HTMLDivElement;
indicator = el.shadowRoot?.querySelector('[part="indicator"]') as HTMLDivElement;
});
it('should render a component that passes accessibility test.', async () => {
await expect(el).to.be.accessible();
});
it('uses the value parameter on the base, as aria-valuenow', async () => {
expect(base).attribute('aria-valuenow', '25');
});
it('appends a % to the value, and uses it as the the value parameter to determine the width on the "indicator" part', async () => {
expect(indicator).attribute('style', 'width:25%;');
});
});
describe('when provided an indeterminate parameter', async () => {
let base: HTMLDivElement;
before(async () => {
el = await fixture<SlProgressBar>(
html`<sl-progress-bar title="Titled Progress Ring" indeterminate></sl-progress-bar>`
);
base = el.shadowRoot?.querySelector('[part="base"]') as HTMLDivElement;
});
it('should render a component that passes accessibility test.', async () => {
await expect(el).to.be.accessible();
});
it('should append a progress-bar--indeterminate class to the "base" part.', async () => {
expect(base.classList.value.trim()).to.eq('progress-bar progress-bar--indeterminate');
});
});
describe('when provided a ariaLabel, and value parameter', async () => {
before(async () => {
el = await fixture<SlProgressBar>(
html`<sl-progress-bar ariaLabel="Labelled Progress Ring" value="25"></sl-progress-bar>`
);
});
it('should render a component that passes accessibility test.', async () => {
await expect(el).to.be.accessible();
});
});
describe('when provided a ariaLabelledBy, and value parameter', async () => {
before(async () => {
el = await fixture<SlProgressBar>(
html`
<label id="labelledby">Progress Ring Label</label>
<sl-progress-bar ariaLabelledBy="labelledby" value="25"></sl-progress-bar>
`
);
});
it('should render a component that passes accessibility test.', async () => {
await expect(el).to.be.accessible();
});
});
});

Wyświetl plik

@ -1,5 +1,6 @@
import { LitElement, html } from 'lit';
import { customElement, property } from 'lit/decorators.js';
import { ifDefined } from 'lit/directives/if-defined.js';
import { classMap } from 'lit/directives/class-map.js';
import { styleMap } from 'lit/directives/style-map.js';
import styles from './progress-bar.styles';
@ -29,6 +30,15 @@ export default class SlProgressBar extends LitElement {
/** When true, percentage is ignored, the label is hidden, and the progress bar is drawn in an indeterminate state. */
@property({ type: Boolean, reflect: true }) indeterminate = false;
/** When set, will place a hoverable title on the progress bar. */
@property() title: string;
/** When set, will place a label on the progress bar. */
@property() ariaLabel: string;
/** When set, will place a labelledby on the progress bar. */
@property() ariaLabelledBy: string;
render() {
return html`
<div
@ -38,9 +48,12 @@ export default class SlProgressBar extends LitElement {
'progress-bar--indeterminate': this.indeterminate
})}
role="progressbar"
title=${ifDefined(this.title)}
aria-label=${ifDefined(this.ariaLabel)}
aria-labelledby=${ifDefined(this.ariaLabelledBy)}
aria-valuemin="0"
aria-valuemax="100"
aria-valuenow="${this.indeterminate ? '' : this.value}"
aria-valuenow="${this.indeterminate ? 0 : this.value}"
>
<div part="indicator" class="progress-bar__indicator" style=${styleMap({ width: this.value + '%' })}>
${!this.indeterminate

Wyświetl plik

@ -0,0 +1,68 @@
import { expect, fixture, html } from '@open-wc/testing';
import '../../../dist/shoelace.js';
import type SlProgressRing from './progress-ring';
describe('<sl-progress-ring>', () => {
let el: SlProgressRing;
describe('when provided just a value parameter', async () => {
before(async () => {
el = await fixture<SlProgressRing>(html`<sl-progress-ring value="25"></sl-progress-ring>`);
});
it('should render a component that does not pass accessibility test.', async () => {
await expect(el).not.to.be.accessible();
});
});
describe('when provided a title, and value parameter', async () => {
let base: HTMLDivElement;
before(async () => {
el = await fixture<SlProgressRing>(
html`<sl-progress-ring title="Titled Progress Ring" value="25"></sl-progress-ring>`
);
base = el.shadowRoot?.querySelector('[part="base"]') as HTMLDivElement;
});
it('should render a component that passes accessibility test.', async () => {
await expect(el).to.be.accessible();
});
it('uses the value parameter on the base, as aria-valuenow', async () => {
expect(base).attribute('aria-valuenow', '25');
});
it('translates the value parameter to a percentage, and uses translation on the base, as percentage css variable', async () => {
expect(base).attribute('style', '--percentage: 0.25');
});
});
describe('when provided a ariaLabel, and value parameter', async () => {
before(async () => {
el = await fixture<SlProgressRing>(
html`<sl-progress-ring ariaLabel="Labelled Progress Ring" value="25"></sl-progress-ring>`
);
});
it('should render a component that passes accessibility test.', async () => {
await expect(el).to.be.accessible();
});
});
describe('when provided a ariaLabelledBy, and value parameter', async () => {
before(async () => {
el = await fixture<SlProgressRing>(
html`
<label id="labelledby">Progress Ring Label</label>
<sl-progress-ring ariaLabelledBy="labelledby" value="25"></sl-progress-ring>
`
);
});
it('should render a component that passes accessibility test.', async () => {
await expect(el).to.be.accessible();
});
});
});

Wyświetl plik

@ -1,5 +1,6 @@
import { LitElement, html } from 'lit';
import { customElement, property, query, state } from 'lit/decorators.js';
import { ifDefined } from 'lit/directives/if-defined.js';
import styles from './progress-ring.styles';
/**
@ -27,6 +28,15 @@ export default class SlProgressRing extends LitElement {
/** The current progress, 0 to 100. */
@property({ type: Number, reflect: true }) value = 0;
/** When set, will place a hoverable title on the progress ring. */
@property() title: string;
/** When set, will place a label on the progress ring. */
@property() ariaLabel: string;
/** When set, will place a labelledby on the progress ring. */
@property() ariaLabelledBy: string;
updated(changedProps: Map<string, any>) {
super.updated(changedProps);
@ -50,6 +60,9 @@ export default class SlProgressRing extends LitElement {
part="base"
class="progress-ring"
role="progressbar"
title=${ifDefined(this.title)}
aria-label=${ifDefined(this.ariaLabel)}
aria-labelledby=${ifDefined(this.ariaLabelledBy)}
aria-valuemin="0"
aria-valuemax="100"
aria-valuenow="${this.value}"