Unverified Commit 9d58f631 by Eric Fischer Committed by GitHub

Merge pull request #59 from edx/efischer/hide_delete_header

Hide table headers when marked hidden
parents db72d5a8 abb93e2d
...@@ -3,3 +3,4 @@ ...@@ -3,3 +3,4 @@
node_modules node_modules
npm-debug.log npm-debug.log
coverage coverage
jest*
...@@ -1241,7 +1241,9 @@ exports[`Storyshots Table default heading 1`] = ` ...@@ -1241,7 +1241,9 @@ exports[`Storyshots Table default heading 1`] = `
className="" className=""
scope="col" scope="col"
> >
Coat Color <span
className="sr-only"
/>
</th> </th>
</tr> </tr>
</thead> </thead>
...@@ -1332,7 +1334,9 @@ exports[`Storyshots Table responsive 1`] = ` ...@@ -1332,7 +1334,9 @@ exports[`Storyshots Table responsive 1`] = `
className="" className=""
scope="col" scope="col"
> >
Coat Color <span
className="sr-only"
/>
</th> </th>
</tr> </tr>
</thead> </thead>
...@@ -1434,56 +1438,18 @@ exports[`Storyshots Table sortable 1`] = ` ...@@ -1434,56 +1438,18 @@ exports[`Storyshots Table sortable 1`] = `
</button> </button>
</th> </th>
<th <th
className="sortable" className=""
scope="col" scope="col"
> >
<button Famous For
className="btn"
onBlur={[Function]}
onClick={[Function]}
onKeyDown={[Function]}
type="button"
>
<span>
Famous For
<span
className="sr-only"
>
click to sort
</span>
<span
className="fa fa-sort"
/>
</span>
</button>
</th> </th>
<th <th
className="sortable" className=""
scope="col" scope="col"
> >
<button <span
className="btn" className="sr-only"
onBlur={[Function]} />
onClick={[Function]}
onKeyDown={[Function]}
type="button"
>
<span>
Coat Color
<span
className="sr-only"
>
click to sort
</span>
<span
className="fa fa-sort"
/>
</span>
</button>
</th> </th>
</tr> </tr>
</thead> </thead>
...@@ -1574,7 +1540,9 @@ exports[`Storyshots Table table-striped 1`] = ` ...@@ -1574,7 +1540,9 @@ exports[`Storyshots Table table-striped 1`] = `
className="" className=""
scope="col" scope="col"
> >
Coat Color <span
className="sr-only"
/>
</th> </th>
</tr> </tr>
</thead> </thead>
...@@ -1665,7 +1633,9 @@ exports[`Storyshots Table unstyled 1`] = ` ...@@ -1665,7 +1633,9 @@ exports[`Storyshots Table unstyled 1`] = `
className="" className=""
scope="col" scope="col"
> >
Coat Color <span
className="sr-only"
/>
</th> </th>
</tr> </tr>
</thead> </thead>
......
...@@ -35,14 +35,21 @@ const catColumns = [ ...@@ -35,14 +35,21 @@ const catColumns = [
{ {
label: 'Name', label: 'Name',
key: 'name', key: 'name',
columnSortable: true,
onSort: () => {},
}, },
{ {
label: 'Famous For', label: 'Famous For',
key: 'famous_for', key: 'famous_for',
columnSortable: false,
onSort: () => {},
}, },
{ {
label: 'Coat Color', label: 'Coat Color',
key: 'color', key: 'color',
columnSortable: false,
hideHeader: true,
onSort: () => {},
}, },
]; ];
...@@ -96,7 +103,6 @@ storiesOf('Table', module) ...@@ -96,7 +103,6 @@ storiesOf('Table', module)
data={catDataSortable.sort((firstElement, secondElement) => sort(firstElement, secondElement, catColumns[0].key, 'desc'))} data={catDataSortable.sort((firstElement, secondElement) => sort(firstElement, secondElement, catColumns[0].key, 'desc'))}
columns={catColumns.map(column => ({ columns={catColumns.map(column => ({
...column, ...column,
columnSortable: true,
onSort(direction) { onSort(direction) {
catDataSortable.sort((firstElement, secondElement) => catDataSortable.sort((firstElement, secondElement) =>
sort(firstElement, secondElement, column.key, direction)); sort(firstElement, secondElement, column.key, direction));
......
...@@ -9,11 +9,12 @@ const props = { ...@@ -9,11 +9,12 @@ const props = {
{ key: 'num', label: 'Number' }, { key: 'num', label: 'Number' },
{ key: 'x2', label: 'Number * 2' }, { key: 'x2', label: 'Number * 2' },
{ key: 'sq', label: 'Number Squared' }, { key: 'sq', label: 'Number Squared' },
{ key: 'i', label: 'Imaginary Number' },
], ],
data: [ data: [
{ sq: 1, num: 1, x2: 2 }, { sq: 1, num: 1, x2: 2, i: 'i' },
{ sq: 4, num: 2, x2: 4 }, { sq: 4, num: 2, x2: 4, i: '2i' },
{ sq: 9, num: 3, x2: 6 }, { sq: 9, num: 3, x2: 6, i: '3i' },
], ],
}; };
...@@ -29,6 +30,10 @@ const sortableColumnProps = { ...@@ -29,6 +30,10 @@ const sortableColumnProps = {
sq: { sq: {
columnSortable: false, columnSortable: false,
}, },
i: {
columnSortable: false,
hideHeader: true,
},
}; };
const sortableColumns = props.columns.map(column => ({ const sortableColumns = props.columns.map(column => ({
...@@ -60,7 +65,9 @@ describe('<Table />', () => { ...@@ -60,7 +65,9 @@ describe('<Table />', () => {
it('with data in the same order as the columns', () => { it('with data in the same order as the columns', () => {
wrapper.find('tr').at(1).find('td').forEach((td, i) => { wrapper.find('tr').at(1).find('td').forEach((td, i) => {
expect(Number(td.text())).toEqual(props.data[0][props.columns[i].key]); let parsed = Number(td.text());
if (isNaN(parsed)) { parsed = td.text(); }
expect(parsed).toEqual(props.data[0][props.columns[i].key]);
}); });
}); });
...@@ -147,7 +154,7 @@ describe('<Table />', () => { ...@@ -147,7 +154,7 @@ describe('<Table />', () => {
it('with correct initial sort icons', () => { it('with correct initial sort icons', () => {
const buttons = wrapper.find('button'); const buttons = wrapper.find('button');
expect(buttons.find('.fa')).toHaveLength(sortableProps.columns.length - 1); expect(buttons.find('.fa')).toHaveLength(sortableProps.columns.length - 2);
expect(buttons.at(0).find('.fa-sort-desc')).toHaveLength(1); expect(buttons.at(0).find('.fa-sort-desc')).toHaveLength(1);
expect(buttons.at(1).find('.fa-sort')).toHaveLength(1); expect(buttons.at(1).find('.fa-sort')).toHaveLength(1);
}); });
......
...@@ -63,24 +63,28 @@ class Table extends React.Component { ...@@ -63,24 +63,28 @@ class Table extends React.Component {
} }
getTableHeading(column) { getTableHeading(column) {
return ( let heading;
this.props.tableSortable && column.columnSortable ? if (this.props.tableSortable && column.columnSortable) {
<Button heading = (<Button
label={ label={
<span> <span>
{column.label} {column.label}
<span className={classNames(styles['sr-only'])}> <span className={classNames(styles['sr-only'])}>
{' '}
{this.getSortButtonScreenReaderText(column.key)}
</span>
{' '} {' '}
{this.getSortIcon(column.key === this.state.sortedColumn ? this.state.sortDirection : '')} {this.getSortButtonScreenReaderText(column.key)}
</span>} </span>
onClick={() => this.onSortClick(column.key)} {' '}
/> {this.getSortIcon(column.key === this.state.sortedColumn ? this.state.sortDirection : '')}
: </span>}
column.label onClick={() => this.onSortClick(column.key)}
); />);
} else if (column.hideHeader) {
heading = (<span className={classNames(styles['sr-only'])} />);
} else {
heading = column.label;
}
return heading;
} }
getHeadings() { getHeadings() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment