Skip to content

Commit afcfeaf

Browse files
Improve template Accessibility (#12891)
Add aria-label to table to give title
1 parent 14f17fa commit afcfeaf

File tree

6 files changed

+74
-74
lines changed

6 files changed

+74
-74
lines changed

src/ProjectTemplates/Web.Spa.ProjectTemplates/content/Angular-CSharp/ClientApp/src/app/counter/counter.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ <h1>Counter</h1>
22

33
<p>This is a simple example of an Angular component.</p>
44

5-
<p>Current count: <strong>{{ currentCount }}</strong></p>
5+
<p aria-live="polite">Current count: <strong>{{ currentCount }}</strong></p>
66

77
<button class="btn btn-primary" (click)="incrementCounter()">Increment</button>

src/ProjectTemplates/Web.Spa.ProjectTemplates/content/Angular-CSharp/ClientApp/src/app/fetch-data/fetch-data.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
<h1>Weather forecast</h1>
1+
<h1 id="tableLabel">Weather forecast</h1>
22

33
<p>This component demonstrates fetching data from the server.</p>
44

55
<p *ngIf="!forecasts"><em>Loading...</em></p>
66

7-
<table class='table table-striped' *ngIf="forecasts">
7+
<table class='table table-striped' aria-labelledby="tableLabel" *ngIf="forecasts">
88
<thead>
99
<tr>
1010
<th>Date</th>

src/ProjectTemplates/Web.Spa.ProjectTemplates/content/React-CSharp/ClientApp/src/components/Counter.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,26 @@ import React, { Component } from 'react';
33
export class Counter extends Component {
44
static displayName = Counter.name;
55

6-
constructor (props) {
6+
constructor(props) {
77
super(props);
88
this.state = { currentCount: 0 };
99
this.incrementCounter = this.incrementCounter.bind(this);
1010
}
1111

12-
incrementCounter () {
12+
incrementCounter() {
1313
this.setState({
1414
currentCount: this.state.currentCount + 1
1515
});
1616
}
1717

18-
render () {
18+
render() {
1919
return (
2020
<div>
2121
<h1>Counter</h1>
2222

2323
<p>This is a simple example of a React component.</p>
2424

25-
<p>Current count: <strong>{this.state.currentCount}</strong></p>
25+
<p aria-live="polite">Current count: <strong>{this.state.currentCount}</strong></p>
2626

2727
<button className="btn btn-primary" onClick={this.incrementCounter}>Increment</button>
2828
</div>

src/ProjectTemplates/Web.Spa.ProjectTemplates/content/React-CSharp/ClientApp/src/components/FetchData.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export class FetchData extends Component {
1717

1818
static renderForecastsTable(forecasts) {
1919
return (
20-
<table className='table table-striped'>
20+
<table className='table table-striped' aria-labelledby="tabelLabel">
2121
<thead>
2222
<tr>
2323
<th>Date</th>
@@ -47,7 +47,7 @@ export class FetchData extends Component {
4747

4848
return (
4949
<div>
50-
<h1>Weather forecast</h1>
50+
<h1 id="tabelLabel" >Weather forecast</h1>
5151
<p>This component demonstrates fetching data from the server.</p>
5252
{contents}
5353
</div>

src/ProjectTemplates/Web.Spa.ProjectTemplates/content/ReactRedux-CSharp/ClientApp/src/components/Counter.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ class Counter extends React.PureComponent<CounterProps> {
1717

1818
<p>This is a simple example of a React component.</p>
1919

20-
<p>Current count: <strong>{this.props.count}</strong></p>
20+
<p aria-live="polite">Current count: <strong>{this.props.count}</strong></p>
2121

2222
<button type="button"
23-
className="btn btn-primary btn-lg"
24-
onClick={() => { this.props.increment(); }}>
23+
className="btn btn-primary btn-lg"
24+
onClick={() => { this.props.increment(); }}>
2525
Increment
2626
</button>
2727
</React.Fragment>

src/ProjectTemplates/Web.Spa.ProjectTemplates/content/ReactRedux-CSharp/ClientApp/src/components/FetchData.tsx

Lines changed: 62 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -7,78 +7,78 @@ import * as WeatherForecastsStore from '../store/WeatherForecasts';
77

88
// At runtime, Redux will merge together...
99
type WeatherForecastProps =
10-
WeatherForecastsStore.WeatherForecastsState // ... state we've requested from the Redux store
11-
& typeof WeatherForecastsStore.actionCreators // ... plus action creators we've requested
12-
& RouteComponentProps<{ startDateIndex: string }>; // ... plus incoming routing parameters
10+
WeatherForecastsStore.WeatherForecastsState // ... state we've requested from the Redux store
11+
& typeof WeatherForecastsStore.actionCreators // ... plus action creators we've requested
12+
& RouteComponentProps<{ startDateIndex: string }>; // ... plus incoming routing parameters
1313

1414

1515
class FetchData extends React.PureComponent<WeatherForecastProps> {
16-
// This method is called when the component is first added to the document
17-
public componentDidMount() {
18-
this.ensureDataFetched();
19-
}
16+
// This method is called when the component is first added to the document
17+
public componentDidMount() {
18+
this.ensureDataFetched();
19+
}
2020

21-
// This method is called when the route parameters change
22-
public componentDidUpdate() {
23-
this.ensureDataFetched();
24-
}
21+
// This method is called when the route parameters change
22+
public componentDidUpdate() {
23+
this.ensureDataFetched();
24+
}
2525

26-
public render() {
27-
return (
28-
<React.Fragment>
29-
<h1>Weather forecast</h1>
30-
<p>This component demonstrates fetching data from the server and working with URL parameters.</p>
31-
{ this.renderForecastsTable() }
32-
{ this.renderPagination() }
33-
</React.Fragment>
34-
);
35-
}
26+
public render() {
27+
return (
28+
<React.Fragment>
29+
<h1 id="tabelLabel">Weather forecast</h1>
30+
<p>This component demonstrates fetching data from the server and working with URL parameters.</p>
31+
{this.renderForecastsTable()}
32+
{this.renderPagination()}
33+
</React.Fragment>
34+
);
35+
}
3636

37-
private ensureDataFetched() {
38-
const startDateIndex = parseInt(this.props.match.params.startDateIndex, 10) || 0;
39-
this.props.requestWeatherForecasts(startDateIndex);
40-
}
37+
private ensureDataFetched() {
38+
const startDateIndex = parseInt(this.props.match.params.startDateIndex, 10) || 0;
39+
this.props.requestWeatherForecasts(startDateIndex);
40+
}
4141

42-
private renderForecastsTable() {
43-
return (
44-
<table className='table table-striped'>
45-
<thead>
46-
<tr>
47-
<th>Date</th>
48-
<th>Temp. (C)</th>
49-
<th>Temp. (F)</th>
50-
<th>Summary</th>
51-
</tr>
52-
</thead>
53-
<tbody>
54-
{this.props.forecasts.map((forecast: WeatherForecastsStore.WeatherForecast) =>
55-
<tr key={forecast.date}>
56-
<td>{forecast.date}</td>
57-
<td>{forecast.temperatureC}</td>
58-
<td>{forecast.temperatureF}</td>
59-
<td>{forecast.summary}</td>
60-
</tr>
61-
)}
62-
</tbody>
63-
</table>
64-
);
65-
}
42+
private renderForecastsTable() {
43+
return (
44+
<table className='table table-striped' aria-labelledby="tabelLabel">
45+
<thead>
46+
<tr>
47+
<th>Date</th>
48+
<th>Temp. (C)</th>
49+
<th>Temp. (F)</th>
50+
<th>Summary</th>
51+
</tr>
52+
</thead>
53+
<tbody>
54+
{this.props.forecasts.map((forecast: WeatherForecastsStore.WeatherForecast) =>
55+
<tr key={forecast.date}>
56+
<td>{forecast.date}</td>
57+
<td>{forecast.temperatureC}</td>
58+
<td>{forecast.temperatureF}</td>
59+
<td>{forecast.summary}</td>
60+
</tr>
61+
)}
62+
</tbody>
63+
</table>
64+
);
65+
}
6666

67-
private renderPagination() {
68-
const prevStartDateIndex = (this.props.startDateIndex || 0) - 5;
69-
const nextStartDateIndex = (this.props.startDateIndex || 0) + 5;
67+
private renderPagination() {
68+
const prevStartDateIndex = (this.props.startDateIndex || 0) - 5;
69+
const nextStartDateIndex = (this.props.startDateIndex || 0) + 5;
7070

71-
return (
72-
<div className="d-flex justify-content-between">
73-
<Link className='btn btn-outline-secondary btn-sm' to={`/fetch-data/${prevStartDateIndex}`}>Previous</Link>
74-
{this.props.isLoading && <span>Loading...</span>}
75-
<Link className='btn btn-outline-secondary btn-sm' to={`/fetch-data/${nextStartDateIndex}`}>Next</Link>
76-
</div>
77-
);
78-
}
71+
return (
72+
<div className="d-flex justify-content-between">
73+
<Link className='btn btn-outline-secondary btn-sm' to={`/fetch-data/${prevStartDateIndex}`}>Previous</Link>
74+
{this.props.isLoading && <span>Loading...</span>}
75+
<Link className='btn btn-outline-secondary btn-sm' to={`/fetch-data/${nextStartDateIndex}`}>Next</Link>
76+
</div>
77+
);
78+
}
7979
}
8080

8181
export default connect(
82-
(state: ApplicationState) => state.weatherForecasts, // Selects which state properties are merged into the component's props
83-
WeatherForecastsStore.actionCreators // Selects which action creators are merged into the component's props
82+
(state: ApplicationState) => state.weatherForecasts, // Selects which state properties are merged into the component's props
83+
WeatherForecastsStore.actionCreators // Selects which action creators are merged into the component's props
8484
)(FetchData as any);

0 commit comments

Comments
 (0)