-
Notifications
You must be signed in to change notification settings - Fork 290
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add roles and aria-attributes for initial screen reader support (Helps …
- Loading branch information
1 parent
dc9d8a7
commit ce39a52
Showing
6 changed files
with
114 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/** | ||
* Copyright Schrodinger, LLC | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* @providesModule ariaAttributes | ||
*/ | ||
import shallowEqualSelector from 'shallowEqualSelector'; | ||
|
||
/** | ||
* Calculate the aria attributes for the rows and the grid. | ||
* | ||
* @param {number} rowsCount | ||
* @param {boolean} useGroupHeader | ||
* @param {boolean} useFooter | ||
* @return {{ | ||
* ariaGroupHeaderIndex: number, | ||
* ariaHeaderIndex: number, | ||
* ariaFooterIndex: number, | ||
* ariaRowCount: number, | ||
* ariaRowIndexOffset: number | ||
* }} | ||
*/ | ||
function calculateAriaAttributes(rowsCount, useGroupHeader, useFooter) { | ||
// first we calculate the default attribute values (without assuming group header or footer exists) | ||
var ariaGroupHeaderIndex = 1; | ||
var ariaHeaderIndex = 1; | ||
var ariaFooterIndex = rowsCount + 2; | ||
var ariaRowCount = rowsCount + 1; | ||
|
||
// offset to add to aria-rowindex (note that aria-rowindex is 1-indexed based, and since | ||
// we also need to add 1 for the header, the base offset will be 2) | ||
var ariaRowIndexOffset = 2; | ||
|
||
// if group header exists, then increase the indices and offsets by 1 | ||
if (useGroupHeader) { | ||
ariaHeaderIndex++; | ||
ariaRowCount++; | ||
ariaFooterIndex++; | ||
ariaRowIndexOffset++; | ||
} | ||
|
||
// if footer exists, then row count increases by 1 | ||
if (useFooter) { | ||
ariaRowCount++; | ||
} | ||
|
||
return { | ||
ariaGroupHeaderIndex, | ||
ariaHeaderIndex, | ||
ariaFooterIndex, | ||
ariaRowCount, | ||
ariaRowIndexOffset, | ||
}; | ||
} | ||
|
||
export default shallowEqualSelector([ | ||
state => state.rowsCount, | ||
state => state.groupHeaderHeight > 0, | ||
state => state.footerHeight > 0, | ||
], calculateAriaAttributes); |