Skip to content

Commit 00e68dc

Browse files
feat: adding loadingText attribute to define aria-valuetext
1 parent 2786b51 commit 00e68dc

File tree

5 files changed

+74
-11
lines changed

5 files changed

+74
-11
lines changed

CHANGELOG.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,38 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased][]
99

10+
### Added
11+
12+
- Adding new `loadingText` attribute to be used as WAI-ARIA `aria-valuetext`. In this case, it will render the component using "Please wait ...". Otherwise, it defaults to "Loading..."
13+
14+
```html
15+
<!-- Passing loading text to be used as WAI-ARIA `aria-valuetext` -->
16+
<!-- In this case, it will render the component using "Please wait ..." -->
17+
<!-- Otherwise, it defaults to "Loading..." -->
18+
<div class="skeleton-with-specific-loading-text">
19+
<ngx-skeleton-loader loadingText="Please wait ..."></ngx-skeleton-loader>
20+
</div>
21+
```
22+
1023
### Updated
1124

1225
- Using OnPush as changeDetection mechanism into ngx-skeleton-loader component
26+
- Adding ability to pass `false` as string or boolean (coming from variable value via binding) on `animation` attribute in `ngx-skeleton-loader` component configuration. animation will receive `false` as string when attribute field it's not using binding. Component now can receive `false` (boolean), "false" (string), or any other animation type via binding.
27+
28+
```html
29+
<div class="item">
30+
<!-- Disables the animation -->
31+
<ngx-skeleton-loader animation="false"></ngx-skeleton-loader>
32+
<!-- Disables the animation, but receiving boolean value from binding -->
33+
<!-- Via binding it can receive `false` (boolean), "false" (string), or any other animation type -->
34+
<ngx-skeleton-loader [animation]="classAttributeWithBooleanFalseValue"></ngx-skeleton-loader>
35+
<!-- Uses `progress` as animation -->
36+
<ngx-skeleton-loader animation="progress"></ngx-skeleton-loader>
37+
<ngx-skeleton-loader></ngx-skeleton-loader>
38+
<!-- Uses `pulse` as animation -->
39+
<ngx-skeleton-loader animation="pulse"></ngx-skeleton-loader>
40+
</div>
41+
```
1342

1443
## [2.6.2][] - 2020-12-08
1544

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,18 @@ export class YourAppComponent {}
114114
</div>
115115
```
116116

117+
## WAI-ARIA values
118+
119+
- loadingText - _default_ `Loading...`: attribute that defines the text value for `aria-valuetext` attribute. Defaults to "Loading..."
120+
117121
## Animations
118122

119123
You can also define which CSS animation you want to use - even not use any, if it's the case - in your skeleton loader by passing the options in your component via `[animation]` attribute.
120124

121125
### Options
122126

123-
- `false`: it will disable the animation;
127+
- `"false"` (as string): it will disable the animation;
128+
- `false` (as boolean): it will disable the animation. Animation will receive `false` as string when attribute field it's not using binding. Component now can receive `false` (boolean), "false" (string), or any other animation type via binding;
124129
- `progress` - _default_: it will use it `progress` as animation;
125130
- `progress-dark`: it will use it `progress-dark` as animation. Recommended if your color schema is darken;
126131
- `pulse`: it will use `pulse` as animation;
@@ -136,6 +141,9 @@ you need to apply the style changes on the
136141
<div class="item">
137142
<!-- Disables the animation -->
138143
<ngx-skeleton-loader animation="false"></ngx-skeleton-loader>
144+
<!-- Disables the animation, but receiving boolean value from binding -->
145+
<!-- Via binding it can receive `false` (boolean), "false" (string), or any other animation type -->
146+
<ngx-skeleton-loader [animation]="classAttributeWithBooleanFalseValue"></ngx-skeleton-loader>
139147
<!-- Uses `progress` as animation -->
140148
<ngx-skeleton-loader animation="progress"></ngx-skeleton-loader>
141149
<ngx-skeleton-loader></ngx-skeleton-loader>

projects/ngx-skeleton-loader/src/lib/ngx-skeleton-loader.component.spec.ts

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,18 @@ import { NgxSkeletonLoaderComponent } from './ngx-skeleton-loader.component';
1111
<ngx-skeleton-loader></ngx-skeleton-loader>
1212
</div>
1313
14+
<div class="skeleton-with-specific-loading-text">
15+
<ngx-skeleton-loader loadingText="Loading. Please wait ..."></ngx-skeleton-loader>
16+
</div>
17+
1418
<div class="skeletons-animation-no-animation">
1519
<ngx-skeleton-loader animation="false"></ngx-skeleton-loader>
1620
</div>
1721
22+
<div class="skeletons-animation-no-animation-via-binding">
23+
<ngx-skeleton-loader [animation]="animationWithFalsePassedViaBinding"></ngx-skeleton-loader>
24+
</div>
25+
1826
<div class="skeletons-animation-pulse">
1927
<ngx-skeleton-loader animation="pulse"></ngx-skeleton-loader>
2028
</div>
@@ -46,7 +54,9 @@ import { NgxSkeletonLoaderComponent } from './ngx-skeleton-loader.component';
4654
</div>
4755
`,
4856
})
49-
class ContainerComponent {}
57+
class ContainerComponent {
58+
animationWithFalsePassedViaBinding = false;
59+
}
5060

5161
describe('NgxSkeletonLoaderComponent', () => {
5262
let fixture: any;
@@ -71,12 +81,12 @@ describe('NgxSkeletonLoaderComponent', () => {
7181
});
7282

7383
it('should add all relevant WAI-ARIA `aria-` attributes in all ngx-skeleton-loader', () => {
74-
expect(fixture.nativeElement.querySelectorAll('[aria-busy="true"]').length).toBe(10);
75-
expect(fixture.nativeElement.querySelectorAll('[aria-valuemin="0"]').length).toBe(10);
76-
expect(fixture.nativeElement.querySelectorAll('[aria-valuemax="100"]').length).toBe(10);
77-
expect(fixture.nativeElement.querySelectorAll('[aria-valuetext="Loading..."]').length).toBe(10);
78-
expect(fixture.nativeElement.querySelectorAll('[role="progressbar"]').length).toBe(10);
79-
expect(fixture.nativeElement.querySelectorAll('[tabindex="0"]').length).toBe(10);
84+
expect(fixture.nativeElement.querySelectorAll('[aria-busy="true"]').length).toBe(12);
85+
expect(fixture.nativeElement.querySelectorAll('[aria-valuemin="0"]').length).toBe(12);
86+
expect(fixture.nativeElement.querySelectorAll('[aria-valuemax="100"]').length).toBe(12);
87+
expect(fixture.nativeElement.querySelectorAll('[aria-valuetext]').length).toBe(12);
88+
expect(fixture.nativeElement.querySelectorAll('[role="progressbar"]').length).toBe(12);
89+
expect(fixture.nativeElement.querySelectorAll('[tabindex="0"]').length).toBe(12);
8090
});
8191

8292
it('should use progress as default animation if `animation` is not passed as component attribute', () => {
@@ -89,6 +99,12 @@ describe('NgxSkeletonLoaderComponent', () => {
8999
});
90100
});
91101

102+
describe('When skeleton is created passing loading text to be used as WAI-ARIA `aria-valuetext`', () => {
103+
it('should render a single skeleton', () => {
104+
expect(fixture.nativeElement.querySelectorAll('[aria-valuetext="Loading. Please wait ..."]').length).toBe(1);
105+
});
106+
});
107+
92108
describe('When skeleton is created with count', () => {
93109
it('should render skeleton based on given count attribute', () => {
94110
expect(fixture.nativeElement.querySelectorAll('.skeletons-with-count .loader').length).toBe(2);
@@ -107,6 +123,13 @@ describe('NgxSkeletonLoaderComponent', () => {
107123
fixture.nativeElement.querySelectorAll('.skeletons-animation-no-animation .loader:not(.animation)').length,
108124
).toBe(1);
109125
});
126+
127+
it('should NOT add progress animation styles based on animation class if animation value is passed via binding', () => {
128+
expect(
129+
fixture.nativeElement.querySelectorAll('.skeletons-animation-no-animation-via-binding .loader:not(.animation)')
130+
.length,
131+
).toBe(1);
132+
});
110133
});
111134

112135
describe('When skeleton is created using `pulse` as animation', () => {

projects/ngx-skeleton-loader/src/lib/ngx-skeleton-loader.component.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,14 @@ export class NgxSkeletonLoaderComponent implements OnInit, AfterViewInit, OnDest
1111
@Input()
1212
count = 1;
1313

14+
@Input()
15+
loadingText = 'Loading...';
16+
1417
@Input()
1518
appearance: 'circle' | '' = '';
1619

1720
@Input()
18-
animation: 'progress' | 'progress-dark' | 'pulse' | 'false' = 'progress';
21+
animation: 'progress' | 'progress-dark' | 'pulse' | 'false' | false = 'progress';
1922

2023
@Input() theme: { [k: string]: string } = {};
2124

@@ -27,7 +30,7 @@ export class NgxSkeletonLoaderComponent implements OnInit, AfterViewInit, OnDest
2730

2831
this.items.length = this.count;
2932
const allowedAnimations = ['progress', 'progress-dark', 'pulse', 'false'];
30-
if (allowedAnimations.indexOf(this.animation) === -1) {
33+
if (allowedAnimations.indexOf(String(this.animation)) === -1) {
3134
// Shows error message only in Development
3235
if (isDevMode()) {
3336
console.error(

projects/ngx-skeleton-loader/src/lib/ngx-skeleton-loader.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
aria-busy="true"
55
aria-valuemin="0"
66
aria-valuemax="100"
7-
aria-valuetext="Loading..."
7+
[attr.aria-valuetext]="loadingText"
88
role="progressbar"
99
tabindex="0"
1010
[ngClass]="{

0 commit comments

Comments
 (0)