Skip to content

Commit

Permalink
Merge pull request #210 from edx/fsheets/hidden-table-headers
Browse files Browse the repository at this point in the history
fix(table): add label to sr only text on hidden table headers
  • Loading branch information
Farhanah Sheets authored Apr 11, 2018
2 parents 5c6daa2 + 71bba05 commit c2804a4
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
24 changes: 18 additions & 6 deletions .storybook/__snapshots__/Storyshots.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -19056,7 +19056,9 @@ exports[`Storyshots Table default heading 1`] = `
>
<span
className="sr-only"
/>
>
Coat Color
</span>
</th>
</tr>
</thead>
Expand Down Expand Up @@ -19212,7 +19214,9 @@ exports[`Storyshots Table fixed 1`] = `
>
<span
className="sr-only"
/>
>
Coat Color
</span>
</th>
</tr>
</thead>
Expand Down Expand Up @@ -19368,7 +19372,9 @@ exports[`Storyshots Table responsive 1`] = `
>
<span
className="sr-only"
/>
>
Coat Color
</span>
</th>
</tr>
</thead>
Expand Down Expand Up @@ -19545,7 +19551,9 @@ exports[`Storyshots Table sortable 1`] = `
>
<span
className="sr-only"
/>
>
Coat Color
</span>
</th>
</tr>
</thead>
Expand Down Expand Up @@ -19701,7 +19709,9 @@ exports[`Storyshots Table table-striped 1`] = `
>
<span
className="sr-only"
/>
>
Coat Color
</span>
</th>
</tr>
</thead>
Expand Down Expand Up @@ -19857,7 +19867,9 @@ exports[`Storyshots Table unstyled 1`] = `
>
<span
className="sr-only"
/>
>
Coat Color
</span>
</th>
</tr>
</thead>
Expand Down
13 changes: 13 additions & 0 deletions src/Table/Table.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,19 @@ describe('<Table />', () => {
describe('that is non-sortable renders', () => {
const wrapper = mount(<Table {...sortableProps} tableSortable={false} />);

it('it sets column headers correctly even with hidden prop', () => {
const tableHeadings = wrapper.find('th');
let hiddenHeader;

tableHeadings.forEach((th, i) => {
expect(th.text()).toEqual(sortableProps.columns[i].label);
if (sortableProps.columns[i].hideHeader) {
hiddenHeader = sortableProps.columns[i].label;
}
});
expect(tableHeadings.find('span').text()).toEqual(hiddenHeader);
});

it('without sortable columns', () => {
const tableHeadings = wrapper.find('th');

Expand Down
2 changes: 1 addition & 1 deletion src/Table/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class Table extends React.Component {
onClick={() => this.onSortClick(column.key)}
/>);
} else if (column.hideHeader) {
heading = (<span className={classNames(styles['sr-only'])} />);
heading = (<span className={classNames(styles['sr-only'])}>{column.label}</span>);
} else {
heading = column.label;
}
Expand Down

0 comments on commit c2804a4

Please sign in to comment.