Commit e6814994 authored by Lynn's avatar Lynn Committed by GitHub

fix: add keyboard accessibility to token selector (#3887)

* fix: add keyboard accessibility to token selector

* fix: update snapshot test

* fix: enable selected of suggested tokens by enter key
Co-authored-by: default avatarLynn Yu <lynn.yu@uniswap.org>
parent fea7d3a8
...@@ -49,6 +49,8 @@ export default function CommonBases({ ...@@ -49,6 +49,8 @@ export default function CommonBases({
const isSelected = selectedCurrency?.equals(currency) const isSelected = selectedCurrency?.equals(currency)
return ( return (
<BaseWrapper <BaseWrapper
tabIndex={0}
onKeyPress={(e) => !isSelected && e.key === 'Enter' && onSelect(currency)}
onClick={() => !isSelected && onSelect(currency)} onClick={() => !isSelected && onSelect(currency)}
disable={isSelected} disable={isSelected}
key={currencyId(currency)} key={currencyId(currency)}
......
...@@ -11,6 +11,7 @@ exports[`renders currency rows correctly when currencies list is non-empty 1`] = ...@@ -11,6 +11,7 @@ exports[`renders currency rows correctly when currencies list is non-empty 1`] =
<div <div
class="sc-bdnxRM Row-sc-u7azg8-0 Row__RowBetween-sc-u7azg8-1 styleds__MenuItem-sc-muzgnq-3 lmTMKd hLLNig hzJkYd firMKT token-item-0x6B175474E89094C44Da98b954EedeAC495271d0F" class="sc-bdnxRM Row-sc-u7azg8-0 Row__RowBetween-sc-u7azg8-1 styleds__MenuItem-sc-muzgnq-3 lmTMKd hLLNig hzJkYd firMKT token-item-0x6B175474E89094C44Da98b954EedeAC495271d0F"
style="position: absolute; left: 0px; top: 0px; height: 56px; width: 100%;" style="position: absolute; left: 0px; top: 0px; height: 56px; width: 100%;"
tabindex="0"
> >
CurrencyLogo currency=DAI CurrencyLogo currency=DAI
<div <div
...@@ -33,6 +34,7 @@ exports[`renders currency rows correctly when currencies list is non-empty 1`] = ...@@ -33,6 +34,7 @@ exports[`renders currency rows correctly when currencies list is non-empty 1`] =
<div <div
class="sc-bdnxRM Row-sc-u7azg8-0 Row__RowBetween-sc-u7azg8-1 styleds__MenuItem-sc-muzgnq-3 lmTMKd hLLNig hzJkYd firMKT token-item-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48" class="sc-bdnxRM Row-sc-u7azg8-0 Row__RowBetween-sc-u7azg8-1 styleds__MenuItem-sc-muzgnq-3 lmTMKd hLLNig hzJkYd firMKT token-item-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"
style="position: absolute; left: 0px; top: 56px; height: 56px; width: 100%;" style="position: absolute; left: 0px; top: 56px; height: 56px; width: 100%;"
tabindex="0"
> >
CurrencyLogo currency=USDC CurrencyLogo currency=USDC
<div <div
...@@ -55,6 +57,7 @@ exports[`renders currency rows correctly when currencies list is non-empty 1`] = ...@@ -55,6 +57,7 @@ exports[`renders currency rows correctly when currencies list is non-empty 1`] =
<div <div
class="sc-bdnxRM Row-sc-u7azg8-0 Row__RowBetween-sc-u7azg8-1 styleds__MenuItem-sc-muzgnq-3 lmTMKd hLLNig hzJkYd firMKT token-item-0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599" class="sc-bdnxRM Row-sc-u7azg8-0 Row__RowBetween-sc-u7azg8-1 styleds__MenuItem-sc-muzgnq-3 lmTMKd hLLNig hzJkYd firMKT token-item-0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599"
style="position: absolute; left: 0px; top: 112px; height: 56px; width: 100%;" style="position: absolute; left: 0px; top: 112px; height: 56px; width: 100%;"
tabindex="0"
> >
CurrencyLogo currency=WBTC CurrencyLogo currency=WBTC
<div <div
......
...@@ -124,8 +124,10 @@ function CurrencyRow({ ...@@ -124,8 +124,10 @@ function CurrencyRow({
// only show add or remove buttons if not on selected list // only show add or remove buttons if not on selected list
return ( return (
<MenuItem <MenuItem
tabIndex={0}
style={style} style={style}
className={`token-item-${key}`} className={`token-item-${key}`}
onKeyPress={(e) => (!isSelected && e.key === 'Enter' ? onSelect() : null)}
onClick={() => (isSelected ? null : onSelect())} onClick={() => (isSelected ? null : onSelect())}
disabled={isSelected} disabled={isSelected}
selected={otherSelected} selected={otherSelected}
......
...@@ -63,7 +63,7 @@ export default function ImportRow({ ...@@ -63,7 +63,7 @@ export default function ImportRow({
const list = token instanceof WrappedTokenInfo ? token.list : undefined const list = token instanceof WrappedTokenInfo ? token.list : undefined
return ( return (
<TokenSection style={style}> <TokenSection tabIndex={0} style={style}>
<CurrencyLogo currency={token} size={'24px'} style={{ opacity: dim ? '0.6' : '1' }} /> <CurrencyLogo currency={token} size={'24px'} style={{ opacity: dim ? '0.6' : '1' }} />
<AutoColumn gap="4px" style={{ opacity: dim ? '0.6' : '1' }}> <AutoColumn gap="4px" style={{ opacity: dim ? '0.6' : '1' }}>
<AutoRow> <AutoRow>
......
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