Skip to content

Commit

Permalink
enhance(accessibility): Add onKeyPress where onClick exists
Browse files Browse the repository at this point in the history
To improve navigability by keyboard-only users.
https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/click-events-have-key-events.md

This is required for eslint-config-airbnb 16+
airbnb/javascript#1482
  • Loading branch information
Empact committed Jan 8, 2018
1 parent f7a41f4 commit 2e4fb87
Show file tree
Hide file tree
Showing 36 changed files with 140 additions and 51 deletions.
2 changes: 1 addition & 1 deletion app/components/ChannelForm/ChannelForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const ChannelForm = ({
parentSelector={() => document.body}
className={styles.modal}
>
<div onClick={closeChannelForm} className={styles.modalClose}>
<div onClick={closeChannelForm} onKeyPress={closeChannelForm} className={styles.modalClose}>
<FaClose />
</div>

Expand Down
5 changes: 3 additions & 2 deletions app/components/ChannelForm/Footer.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@ const Footer = ({ step, changeStep, stepTwoIsValid, submit }) => {

const rightButtonText = step === 4 ? 'Submit' : 'Next'
const rightButtonOnClick = step === 4 ? () => submit() : nextFunc
const backButtonOnClick = () => changeStep(step - 1)

return (
<div className={styles.footer}>
<div className='buttonContainer'>
<div className='buttonPrimary' onClick={() => changeStep(step - 1)}>
<div className='buttonPrimary' onClick={backButtonOnClick} onKeyPress={backButtonOnClick}>
Back
</div>
</div>
<div className='buttonContainer' onClick={rightButtonOnClick}>
<div className='buttonContainer' onClick={rightButtonOnClick} onKeyPress={rightButtonOnClick}>
<div className={`buttonPrimary ${nextIsInactive && 'inactive'}`}>
{rightButtonText}
</div>
Expand Down
1 change: 1 addition & 0 deletions app/components/ChannelForm/StepOne.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class StepOne extends Component {
key={peer.peer_id}
className={styles.peer}
onClick={() => this.peerClicked(peer)}
onKeyPress={() => this.peerClicked(peer)}
>
<h4>{peer.address}</h4>
<h1>{peer.pub_key}</h1>
Expand Down
1 change: 1 addition & 0 deletions app/components/Channels/Channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const Channel = ({ ticker, channel, closeChannel, currentTicker }) => (
<p
className={styles.close}
onClick={() => closeChannel({ channel_point: channel.channel_point })}
onKeyPress={() => closeChannel({ channel_point: channel.channel_point })}
>
Close channel
</p>
Expand Down
3 changes: 2 additions & 1 deletion app/components/Channels/ChannelForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ const ChannelForm = ({ form, setForm, ticker, peers, openChannel, currentTicker
key={peer.peer_id}
className={styles.peer}
onClick={() => setForm({ node_key: peer.pub_key })}
onKeyPress={() => setForm({ node_key: peer.pub_key })}
>
<h4>{peer.address}</h4>
<h1>{peer.pub_key}</h1>
Expand All @@ -107,7 +108,7 @@ const ChannelForm = ({ form, setForm, ticker, peers, openChannel, currentTicker
</ul>

<div className={styles.buttonGroup}>
<div className={styles.button} onClick={submitClicked}>Submit</div>
<div className={styles.button} onClick={submitClicked} onKeyPress={submitClicked}>Submit</div>
</div>
</div>
</ReactModal>
Expand Down
10 changes: 7 additions & 3 deletions app/components/Channels/ChannelModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@ const ChannelModal = ({ isOpen, resetChannel, channel, explorerLinkBase, closeCh
}
}

const closeChannelClicked = () => {
const onCloseChannel = () => {
closeChannel({ channel_point: channel.channel_point })
resetChannel(null)
}

const onSelectChannel = () =>
shell.openExternal(`${explorerLinkBase}/tx/${channel.channel_point.split(':')[0]}`)

return (
<ReactModal
isOpen={isOpen}
Expand All @@ -44,7 +47,8 @@ const ChannelModal = ({ isOpen, resetChannel, channel, explorerLinkBase, closeCh
<h2
data-hint='Channel point'
className='hint--top-left'
onClick={() => shell.openExternal(`${explorerLinkBase}/tx/${channel.channel_point.split(':')[0]}`)}
onClick={onSelectChannel}
onKeyPress={onSelectChannel}
>
{channel.channel_point}
</h2>
Expand Down Expand Up @@ -76,7 +80,7 @@ const ChannelModal = ({ isOpen, resetChannel, channel, explorerLinkBase, closeCh
<dd>{channel.num_updates}</dd>
</dl>
</div>
<div className={styles.close} onClick={closeChannelClicked}>
<div className={styles.close} onClick={onCloseChannel} onKeyPress={onCloseChannel}>
<div>Close channel</div>
</div>
<footer className={styles.active}>
Expand Down
1 change: 1 addition & 0 deletions app/components/Channels/Channels.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ const Channels = ({
className={`${styles.openChannel} hint--top`}
data-hint='Open a channel'
onClick={() => setChannelForm({ isOpen: true })}
onKeyPress={() => setChannelForm({ isOpen: true })}
>
<TiPlus />
</div>
Expand Down
6 changes: 5 additions & 1 deletion app/components/Channels/ClosedPendingChannel.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import { btc } from 'utils'
import styles from './ClosedPendingChannel.scss'

const ClosedPendingChannel = ({ ticker, channel: { channel, closing_txid }, currentTicker, explorerLinkBase }) => (
<li className={styles.channel} onClick={() => shell.openExternal(`${explorerLinkBase}/tx/${closing_txid}`)}>
<li
className={styles.channel}
onClick={() => shell.openExternal(`${explorerLinkBase}/tx/${closing_txid}`)}
onKeyPress={() => shell.openExternal(`${explorerLinkBase}/tx/${closing_txid}`)}
>
<h1 className={styles.closing}>Closing Channel...</h1>
<div className={styles.left}>
<section className={styles.remotePubkey}>
Expand Down
6 changes: 5 additions & 1 deletion app/components/Channels/OpenPendingChannel.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import { btc } from 'utils'
import styles from './OpenPendingChannel.scss'

const OpenPendingChannel = ({ ticker, channel, currentTicker, explorerLinkBase }) => (
<li className={styles.channel} onClick={() => shell.openExternal(`${explorerLinkBase}/tx/${channel.channel.channel_point.split(':')[0]}`)}>
<li
className={styles.channel}
onClick={() => shell.openExternal(`${explorerLinkBase}/tx/${channel.channel.channel_point.split(':')[0]}`)}
onKeyPress={() => shell.openExternal(`${explorerLinkBase}/tx/${channel.channel.channel_point.split(':')[0]}`)}
>
<div className={styles.pending}>
<h1>Opening Channel...</h1>
<span>Blocks till open: {channel.blocks_till_open}</span>
Expand Down
2 changes: 1 addition & 1 deletion app/components/Form/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const Form = ({ formType, formProps, closeForm }) => {
return (
<div className={`${styles.outtercontainer} ${formType && styles.open}`}>
<div className={styles.innercontainer}>
<div className={styles.esc} onClick={closeForm}>
<div className={styles.esc} onClick={closeForm} onKeyPress={closeForm}>
<FaClose />
</div>

Expand Down
8 changes: 7 additions & 1 deletion app/components/Form/PayForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,13 @@ class PayForm extends Component {
</section>
</div>
<section className={styles.buttonGroup}>
<div className={`buttonPrimary ${styles.button} ${isValid && styles.active}`} onClick={onPaySubmit}>Pay</div>
<div
className={`buttonPrimary ${styles.button} ${isValid && styles.active}`}
onClick={onPaySubmit}
onKeyPress={onPaySubmit}
>
Pay
</div>
</section>
</div>
)
Expand Down
2 changes: 1 addition & 1 deletion app/components/Form/RequestForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const RequestForm = ({
/>
</section>
<section className={styles.buttonGroup}>
<div className={`buttonPrimary ${styles.button}`} onClick={onRequestSubmit}>
<div className={`buttonPrimary ${styles.button}`} onClick={onRequestSubmit} onKeyPress={onRequestSubmit}>
Request
</div>
</section>
Expand Down
2 changes: 1 addition & 1 deletion app/components/GlobalError/GlobalError.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class GlobalError extends React.Component {
return (
<div className={`${styles.container} ${!error && styles.closed}`}>
<div className={styles.content}>
<div className={styles.close} onClick={clearError}>
<div className={styles.close} onClick={clearError} onKeyPress={clearError}>
<MdClose />
</div>
<h2>{error}</h2>
Expand Down
1 change: 1 addition & 0 deletions app/components/LndSyncing/LndSyncing.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class LndSyncing extends Component {
className={`${styles.factButton} ${currentFact === index && styles.active}`}
key={index}
onClick={() => this.setState({ currentFact: index })}
onKeyPress={() => this.setState({ currentFact: index })}
/>
))
}
Expand Down
2 changes: 1 addition & 1 deletion app/components/ModalRoot/ModalRoot.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const ModalRoot = ({ modalType, modalProps, hideModal, currentTicker, currency }
return (
<div className={styles.container}>
<div className={styles.content}>
<div className={styles.esc} onClick={hideModal}>
<div className={styles.esc} onClick={hideModal} onKeyPress={hideModal}>
<FaClose />
</div>

Expand Down
5 changes: 3 additions & 2 deletions app/components/ModalRoot/SuccessfulSendCoins.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,19 @@ import styles from './SuccessfulSendCoins.scss'

const SuccessfulSendCoins = ({ amount, addr, txid, hideModal, currentTicker, currency }) => {
const calculatedAmount = currency === 'usd' ? btc.satoshisToUsd(amount, currentTicker.price_usd) : btc.satoshisToBtc(amount)
const showTransaction = () => shell.openExternal(`https://testnet.smartbit.com.au/tx/${txid}`)

return (
<div className={styles.container}>
<AnimatedCheckmark />
<h1>
You&nbsp;
<span className={styles.link} onClick={() => shell.openExternal(`https://testnet.smartbit.com.au/tx/${txid}`)}>sent</span>&nbsp;
<span className={styles.link} onClick={showTransaction} onKeyPress={showTransaction}>sent</span>&nbsp;
<span className={styles.amount}>{calculatedAmount} {currency.toUpperCase()}</span>&nbsp;
to&nbsp;
<span className={styles.addr}>{addr}</span>
</h1>
<div className={styles.button} onClick={hideModal}>
<div className={styles.button} onClick={hideModal} onKeyPress={hideModal}>
Done
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/components/ModalRoot/SuccessfulSendPayment.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const SuccessfulSendPayment = ({ hideModal }) => (
<h1>
<span>Successfully sent payment</span>&nbsp;
</h1>
<div className={styles.button} onClick={hideModal}>
<div className={styles.button} onClick={hideModal} onKeyPress={hideModal}>
Done
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions app/components/Nav/Nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ const Nav = ({ openPayForm, openRequestForm }) => (
</NavLink>
</ul>
<div className={styles.buttons}>
<div className={`buttonPrimary ${styles.button}`} onClick={openPayForm}>
<div className={`buttonPrimary ${styles.button}`} onClick={openPayForm} onKeyPress={openPayForm}>
<span>Pay</span>
</div>
<div className={`buttonPrimary ${styles.button}`} onClick={openRequestForm}>
<div className={`buttonPrimary ${styles.button}`} onClick={openRequestForm} onKeyPress={openRequestForm}>
<span>Request</span>
</div>
</div>
Expand Down
14 changes: 12 additions & 2 deletions app/components/Network/ChannelsList.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,22 @@ const ChannelsList = ({ channels, updateSelectedChannels, selectedChannelIds })
<ul className={styles.channels}>
{
channels.map(channel => (
<li key={channel.chan_id} className={styles.channel} onClick={() => updateSelectedChannels(channel)}>
<li
key={channel.chan_id}
className={styles.channel}
onClick={() => updateSelectedChannels(channel)}
onKeyPress={() => updateSelectedChannels(channel)}
>
<span className={`${styles.dot} ${selectedChannelIds.includes(channel.chan_id) && styles.active}`} />

<header>
<h1>Capacity: {btc.satoshisToBtc(channel.capacity)}</h1>
<span onClick={() => shell.openExternal(`https://testnet.smartbit.com.au/tx/${channel.channel_point.split(':')[0]}`)}>Channel Point</span>
<span
onClick={() => shell.openExternal(`https://testnet.smartbit.com.au/tx/${channel.channel_point.split(':')[0]}`)}
onKeyPress={() => shell.openExternal(`https://testnet.smartbit.com.au/tx/${channel.channel_point.split(':')[0]}`)}
>
Channel Point
</span>
</header>

<section>
Expand Down
2 changes: 1 addition & 1 deletion app/components/Network/PeersList.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const PeersList = ({ peers, updateSelectedPeers, selectedPeerPubkeys }) => (
<ul className={styles.peers}>
{
peers.map(peer => (
<li key={peer.peer_id} className={styles.peer} onClick={() => updateSelectedPeers(peer)}>
<li key={peer.peer_id} className={styles.peer} onClick={() => updateSelectedPeers(peer)} onKeyPress={() => updateSelectedPeers(peer)}>
<span className={`${styles.dot} ${selectedPeerPubkeys.includes(peer.pub_key) && styles.active}`} />
<h1>{peer.address}</h1>
<h4>{peer.pub_key}</h4>
Expand Down
7 changes: 6 additions & 1 deletion app/components/Network/TransactionForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ const TransactionForm = ({ updatePayReq, pay_req, loadingRoutes, payReqRoutes, s
<ul className={styles.routes}>
{
payReqRoutes.map((route, index) => (
<li className={`${styles.route} ${currentRoute === route && styles.active}`} key={index} onClick={() => setCurrentRoute(route)}>
<li
className={`${styles.route} ${currentRoute === route && styles.active}`}
key={index}
onClick={() => setCurrentRoute(route)}
onKeyPress={() => setCurrentRoute(route)}
>
<header>
<h1>Route #{index + 1}</h1>
<span>Hops: {route.hops.length}</span>
Expand Down
2 changes: 1 addition & 1 deletion app/components/Peers/Peer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import PropTypes from 'prop-types'
import styles from './Peer.scss'

const Peer = ({ peer, setPeer }) => (
<li className={styles.peer} onClick={() => setPeer(peer)}>
<li className={styles.peer} onClick={() => setPeer(peer)} onKeyPress={() => setPeer(peer)}>
<h4>{peer.address}</h4>
<h1>{peer.pub_key}</h1>
</li>
Expand Down
6 changes: 4 additions & 2 deletions app/components/Peers/PeerForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ const PeerForm = ({ form, setForm, connect }) => {
connect({ pubkey, host })
}

const onClose = () => setForm({ isOpen: false })

return (
<div>
<ReactModal
Expand All @@ -21,7 +23,7 @@ const PeerForm = ({ form, setForm, connect }) => {
parentSelector={() => document.body}
className={styles.modal}
>
<div onClick={() => setForm({ isOpen: false })} className={styles.modalClose}>
<div onClick={onClose} onKeyPress={onClose} className={styles.modalClose}>
<FaClose />
</div>

Expand Down Expand Up @@ -51,7 +53,7 @@ const PeerForm = ({ form, setForm, connect }) => {
/>
</section>

<div className='buttonContainer' onClick={submit}>
<div className='buttonContainer' onClick={submit} onKeyPress={submit}>
<div className='buttonPrimary'>
Submit
</div>
Expand Down
7 changes: 5 additions & 2 deletions app/components/Peers/PeerModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ const PeerModal = ({ isOpen, resetPeer, peer, disconnect }) => {
}
}

const onClose = () => resetPeer(null)
const onDisconnect = () => disconnect({ pubkey: peer.pub_key })

return (
<ReactModal
isOpen={isOpen}
Expand All @@ -35,7 +38,7 @@ const PeerModal = ({ isOpen, resetPeer, peer, disconnect }) => {
style={customStyles}
>
<div className={styles.closeContainer}>
<span onClick={() => resetPeer(null)}>
<span onClick={onClose} onKeyPress={onClose}>
<FaClose />
</span>
</div>
Expand All @@ -59,7 +62,7 @@ const PeerModal = ({ isOpen, resetPeer, peer, disconnect }) => {
<dd>{peer.bytes_sent}</dd>
</dl>
</div>
<div className={styles.close} onClick={() => disconnect({ pubkey: peer.pub_key })}>
<div className={styles.close} onClick={onDisconnect} onKeyPress={onDisconnect}>
<div>Disconnect peer</div>
</div>
</div>
Expand Down
Loading

0 comments on commit 2e4fb87

Please sign in to comment.