diff --git a/components/select/src/single-select-a11y/__stories__/WithoutOptionsAndLoading.js b/components/select/src/single-select-a11y/__stories__/WithoutOptionsAndLoading.js new file mode 100644 index 000000000..1b8236cdf --- /dev/null +++ b/components/select/src/single-select-a11y/__stories__/WithoutOptionsAndLoading.js @@ -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 ( + option.value === value).label + : '' + } + onChange={(nextValue) => setValue(nextValue)} + options={[]} + /> + ) +} diff --git a/components/select/src/single-select-a11y/__stories__/WithoutSelection.js b/components/select/src/single-select-a11y/__stories__/WithoutSelection.js index aa17177f9..abcf0fe83 100644 --- a/components/select/src/single-select-a11y/__stories__/WithoutSelection.js +++ b/components/select/src/single-select-a11y/__stories__/WithoutSelection.js @@ -7,6 +7,7 @@ export const WithoutSelection = () => { return ( setValue(nextValue)} diff --git a/components/select/src/single-select-a11y/menu/menu-filter.js b/components/select/src/single-select-a11y/menu/filter.js similarity index 96% rename from components/select/src/single-select-a11y/menu/menu-filter.js rename to components/select/src/single-select-a11y/menu/filter.js index 828ed0ec5..a16ba3c6b 100644 --- a/components/select/src/single-select-a11y/menu/menu-filter.js +++ b/components/select/src/single-select-a11y/menu/filter.js @@ -4,7 +4,7 @@ import PropTypes from 'prop-types' import React from 'react' import i18n from '../../locales/index.js' -export function MenuFilter({ +export function Filter({ dataTest, idPrefix, label, @@ -46,7 +46,7 @@ export function MenuFilter({ ) } -MenuFilter.propTypes = { +Filter.propTypes = { idPrefix: PropTypes.string.isRequired, value: PropTypes.string.isRequired, onChange: PropTypes.func.isRequired, diff --git a/components/select/src/single-select-a11y/menu/menu-loading.js b/components/select/src/single-select-a11y/menu/loading.js similarity index 93% rename from components/select/src/single-select-a11y/menu/menu-loading.js rename to components/select/src/single-select-a11y/menu/loading.js index 936db6391..fc57e0a0f 100644 --- a/components/select/src/single-select-a11y/menu/menu-loading.js +++ b/components/select/src/single-select-a11y/menu/loading.js @@ -3,7 +3,7 @@ import { CircularLoader } from '@dhis2-ui/loader' import PropTypes from 'prop-types' import React from 'react' -export function MenuLoading({ message }) { +export function Loading({ message }) { return (
@@ -33,6 +33,6 @@ export function MenuLoading({ message }) { ) } -MenuLoading.propTypes = { +Loading.propTypes = { message: PropTypes.string, } diff --git a/components/select/src/single-select-a11y/menu/menu.js b/components/select/src/single-select-a11y/menu/menu.js index 9d2506b28..26b751f23 100644 --- a/components/select/src/single-select-a11y/menu/menu.js +++ b/components/select/src/single-select-a11y/menu/menu.js @@ -1,15 +1,14 @@ import { colors, elevations } from '@dhis2/ui-constants' import { Layer } from '@dhis2-ui/layer' import { Popper } from '@dhis2-ui/popper' -import cx from 'classnames' import PropTypes from 'prop-types' import React, { useEffect, useState } from 'react' import { optionProp } from '../shared-prop-types.js' import { Empty } from './empty.js' -import { MenuFilter } from './menu-filter.js' -import { MenuLoading } from './menu-loading.js' -import { MenuOptionsList } from './menu-options-list.js' +import { Filter } from './filter.js' +import { Loading } from './loading.js' import { NoMatch } from './no-match.js' +import { OptionsList } from './options-list.js' export function Menu({ comboBoxId, @@ -42,12 +41,12 @@ export function Menu({ onFilterChange, onFilterInputKeyDown, }) { - const [menuWidth, setMenuWidth] = useState('auto') + const [menuWidth, setWidth] = useState('auto') const dataTestPrefix = `${dataTest}-menu` useEffect(() => { if (selectRef) { - const callback = () => setMenuWidth(`${selectRef.offsetWidth}px`) + const callback = () => setWidth(`${selectRef.offsetWidth}px`) callback() // We want to know the width as soon as the selectRef.addEventListener('resize', callback) @@ -75,13 +74,10 @@ export function Menu({ placement="bottom-start" observeReferenceResize > -