-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(select a11y): handle remaining TODO comments & rename internal co…
…mponents
- Loading branch information
Showing
16 changed files
with
167 additions
and
156 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
components/select/src/single-select-a11y/__stories__/WithoutOptionsAndLoading.js
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,28 @@ | ||
import React, { useState } from 'react' | ||
import { SingleSelectA11y } from '../single-select-a11y.js' | ||
|
||
const options = [ | ||
{ label: 'None', value: '' }, | ||
{ value: '1', label: 'Option 1' }, | ||
{ value: '2', label: 'Option 2' }, | ||
{ value: '3', label: 'Option 3' }, | ||
] | ||
|
||
export const WithoutOptionsAndLoading = () => { | ||
const [value, setValue] = useState('') | ||
|
||
return ( | ||
<SingleSelectA11y | ||
loading | ||
idPrefix="a11y" | ||
value={value} | ||
valueLabel={ | ||
value | ||
? options.find((option) => option.value === value).label | ||
: '' | ||
} | ||
onChange={(nextValue) => setValue(nextValue)} | ||
options={[]} | ||
/> | ||
) | ||
} |
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
90 changes: 90 additions & 0 deletions
90
components/select/src/single-select-a11y/selected-value/clear-button.js
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,90 @@ | ||
import { colors, theme } from '@dhis2/ui-constants' | ||
import { Tooltip } from '@dhis2-ui/tooltip' | ||
import PropTypes from 'prop-types' | ||
import React from 'react' | ||
import i18n from '../../locales/index.js' | ||
|
||
function ClearButton({ onClear, clearText, dataTest }) { | ||
return ( | ||
<button | ||
aria-label={i18n.t('{{clearText}}', { clearText })} | ||
data-test={dataTest} | ||
onClick={(e) => { | ||
e.stopPropagation() | ||
onClear(e) | ||
}} | ||
> | ||
<svg | ||
width="16" | ||
height="16" | ||
viewBox="0 0 16 16" | ||
fill="none" | ||
xmlns="http://www.w3.org/2000/svg" | ||
> | ||
<path | ||
d="M8 16A8 8 0 1 0 8 0a8 8 0 0 0 0 16Zm3.536-5.879a1 1 0 1 1-1.415 1.414l-2.12-2.12-2.122 2.121a1 1 0 1 1-1.415-1.414L6.586 8 4.464 5.878A1 1 0 1 1 5.88 4.464L8 6.586l2.121-2.121a1 1 0 1 1 1.415 1.414L9.415 8l2.12 2.121Z" | ||
fill="none" | ||
/> | ||
</svg> | ||
<style jsx>{` | ||
button { | ||
background: none; | ||
border: none; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
cursor: pointer; | ||
height: 24px; | ||
width: 24px; | ||
border-radius: 3px; | ||
} | ||
button svg path { | ||
fill: ${colors.grey500}; | ||
} | ||
button:hover svg path { | ||
fill: ${colors.grey800}; | ||
} | ||
button:hover { | ||
background: ${colors.grey200}; | ||
} | ||
button:focus { | ||
outline: 2px solid ${theme.focus}; | ||
} | ||
`}</style> | ||
</button> | ||
) | ||
} | ||
|
||
ClearButton.propTypes = { | ||
clearText: PropTypes.string.isRequired, | ||
onClear: PropTypes.func.isRequired, | ||
dataTest: PropTypes.string, | ||
} | ||
|
||
function ClearButtonWithTooltip({ onClear, clearText, dataTest }) { | ||
const clearButton = ( | ||
<ClearButton | ||
onClear={onClear} | ||
dataTest={dataTest} | ||
clearText={clearText} | ||
/> | ||
) | ||
|
||
if (!clearText) { | ||
return clearButton | ||
} | ||
|
||
return ( | ||
<Tooltip openDelay={500} content={clearText}> | ||
{clearButton} | ||
</Tooltip> | ||
) | ||
} | ||
|
||
ClearButtonWithTooltip.propTypes = { | ||
clearText: PropTypes.string.isRequired, | ||
onClear: PropTypes.func.isRequired, | ||
dataTest: PropTypes.string, | ||
} | ||
|
||
export { ClearButtonWithTooltip as ClearButton } |
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
Oops, something went wrong.