-
Notifications
You must be signed in to change notification settings - Fork 358
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: updated a11y component * fix: allow note to be focusable * fix: remove dead hotkey code
- Loading branch information
Showing
7 changed files
with
90 additions
and
86 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"arrowParens": "avoid", | ||
"bracketSpacing": true, | ||
"htmlWhitespaceSensitivity": "css", | ||
"insertPragma": false, | ||
"jsxBracketSameLine": false, | ||
"jsxSingleQuote": false, | ||
"printWidth": 120, | ||
"quoteProps": "preserve", | ||
"singleQuote": true, | ||
"trailingComma": "all" | ||
} |
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 |
---|---|---|
@@ -1,54 +1,62 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { connect } from 'react-redux'; | ||
|
||
import React, { useState } from 'react'; | ||
import { useSelector, useDispatch } from 'react-redux'; | ||
import selectors from 'selectors'; | ||
|
||
import './Accessibility.scss'; | ||
import classNames from 'classnames'; | ||
import actions from 'actions'; | ||
|
||
class Accessibility extends React.PureComponent { | ||
static propTypes = { | ||
isAccessibleMode: PropTypes.bool, | ||
isNotesPanelDisabled: PropTypes.bool, | ||
} | ||
function Accessibility() { | ||
const dispatch = useDispatch(); | ||
const [isVisible, setIsVisible] = useState(false); | ||
|
||
state = { | ||
isVisible: false, | ||
} | ||
const isAccessibleMode = useSelector(selectors.isAccessibleMode); | ||
|
||
onFocus = () => { | ||
this.setState({ isVisible: true }); | ||
} | ||
const isNotesPanelOpen = useSelector(state => selectors.isElementOpen(state, 'notesPanel')); | ||
const isNotesPanelDisabled = useSelector(state => selectors.isElementDisabled(state, 'notesPanel')); | ||
|
||
onBlur = () => { | ||
this.setState({ isVisible: false }); | ||
} | ||
const isSearchPanelOpen = useSelector(state => selectors.isElementOpen(state, 'searchPanel')); | ||
const isSearchPanelDisabled = useSelector(state => selectors.isElementDisabled(state, 'searchPanel')); | ||
|
||
render() { | ||
const { isAccessibleMode, isNotesPanelDisabled } = this.props; | ||
const { isVisible } = this.state; | ||
const onFocus = () => setIsVisible(true); | ||
const onBlur = () => setIsVisible(false); | ||
|
||
if (!isAccessibleMode) { | ||
return null; | ||
const onSkipToDocument = () => { | ||
document.getElementById('pageText1').focus(); | ||
}; | ||
|
||
const onSkipToSearch = () => { | ||
if (isSearchPanelOpen) { | ||
const searchEl = document.getElementById('SearchPanel__input'); | ||
searchEl && searchEl.focus(); | ||
} else { | ||
dispatch(actions.openElement('searchPanel')); | ||
} | ||
}; | ||
|
||
const onSkipToNotes = () => { | ||
if (isNotesPanelOpen) { | ||
const noteEl = document.getElementById('NotesPanel__input'); | ||
noteEl && noteEl.focus(); | ||
} else { | ||
dispatch(actions.openElement('notesPanel')); | ||
} | ||
}; | ||
|
||
const skiptoNotes = isNotesPanelDisabled ? null : <div className="skip-to-notes" onFocus={this.onFocus} onBlur={this.onBlur} tabIndex={0}>Notes</div>; | ||
const className = `Accessibility ${isVisible ? 'visible' : 'hidden'}`; | ||
|
||
return ( | ||
<div className={className} data-element="accessibility"> | ||
<div>Skip to: </div> | ||
<input className="skip-to-hack" tabIndex={-1}></input> | ||
<div className="skip-to-document" onFocus={this.onFocus} onBlur={this.onBlur} tabIndex={0}>Document</div> | ||
{skiptoNotes} | ||
</div> | ||
); | ||
if (!isAccessibleMode) { | ||
return null; | ||
} | ||
} | ||
|
||
const mapStateToProps = state => ({ | ||
isAccessibleMode: selectors.isAccessibleMode(state), | ||
isNotesPanelDisabled: selectors.isElementDisabled(state, 'notesPanel') | ||
}); | ||
const a11yClass = classNames('Accessibility', isVisible ? 'visible' : 'hidden'); | ||
|
||
return ( | ||
<div className={a11yClass} data-element="accessibility" onFocus={onFocus} onBlur={onBlur}> | ||
<div>Skip to: </div> | ||
|
||
<button onClick={onSkipToDocument}>Document</button> | ||
{isSearchPanelDisabled ? null : <button onClick={onSkipToSearch}>Search</button>} | ||
{isNotesPanelDisabled ? null : <button onClick={onSkipToNotes}>Notes</button>} | ||
</div> | ||
); | ||
} | ||
|
||
export default connect(mapStateToProps)(Accessibility); | ||
export default Accessibility; |
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