Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ import InputWithClearUI from '../InputWithClearUI/index.js'

const MoleculeAutosuggestSingleSelection = ({
autoFocus,
'aria-expanded': ariaExpanded,
ariaLabel,
autoComplete = 'nope',
children,
design,
disabled,
iconClear,
id,
dropdownListId,
innerRefInput: refInput = {},
inputMode,
isOpen,
Expand Down Expand Up @@ -64,6 +66,11 @@ const MoleculeAutosuggestSingleSelection = ({
return (
<>
<InputWithClearUI
role="combobox"
aria-haspopup="true"
aria-autocomplete="list"
aria-controls={dropdownListId}
aria-expanded={ariaExpanded}
ariaLabel={ariaLabel}
autoComplete={autoComplete}
autoFocus={autoFocus}
Expand Down Expand Up @@ -94,6 +101,8 @@ const MoleculeAutosuggestSingleSelection = ({
</InputWithClearUI>
{(value || isOpen) && (
<MoleculeDropdownList
id={dropdownListId}
aria-labelledby={id}
size={size}
onSelect={handleSelection}
visible={isOpen && Children.count(children) > 0}
Expand Down
13 changes: 9 additions & 4 deletions components/molecule/autosuggest/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ const MoleculeAutosuggest = ({
}
)

const accessibilityProps = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set it into the object directly (if it is used only once) or define it outside of the component fn cycle

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is that the object that’s already created is related to the autosuggest (autosuggestSelectionProps), but not to the wrapper div. Defining it outside the component isn’t possible either, since I’m using a prop value.

tabIndex: '0',
role: 'combobox',
'aria-expanded': isOpenState,
...(multiselection && {'aria-controls': id})
}

const closeList = ev => {
const {current: domMoleculeAutosuggest} = innerRefMoleculeAutosuggest
handleToggle(ev, {isOpen: false})
Expand Down Expand Up @@ -209,6 +216,7 @@ const MoleculeAutosuggest = ({
onSelect,
onToggle: handleToggle,
state,
...(!multiselection && {...accessibilityProps}),
...restProps
}

Expand All @@ -219,15 +227,12 @@ const MoleculeAutosuggest = ({
return (
<div
ref={refMoleculeAutosuggest}
tabIndex="0"
className={className}
onKeyDown={handleKeyDown}
onFocus={handleFocusIn}
onBlur={handleFocusOut}
onClick={handleClick}
role="combobox"
aria-controls={id}
aria-expanded={isOpenState}
{...(multiselection && {...accessibilityProps})}
>
<AutosuggestSelection {...autosuggestSelectionProps} />
</div>
Expand Down
29 changes: 13 additions & 16 deletions components/molecule/autosuggest/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,11 @@ describe(json.name, () => {

// When
const {getByRole} = setup(props)
const autoSuggestElement = getByRole('combobox')
const autoSuggestInputElement = getByRole('textbox')
const autoSuggestInputElement = getByRole('combobox')

// Then
expect(() => getByRole('listbox')).to.throw()
expect(() => getByRole('option')).to.throw()
expect(autoSuggestElement.innerHTML).to.be.a('string')
expect(autoSuggestElement.innerHTML).to.not.have.lengthOf(0)
expect(autoSuggestInputElement.value).to.equal('')
})

Expand All @@ -187,11 +184,11 @@ describe(json.name, () => {

// When
const {getByRole, getAllByRole} = setup(props)
const combo = getByRole('combobox')

// Then
expect(getByRole('combobox').innerHTML).to.be.a('string')
expect(getByRole('combobox').innerHTML).to.not.have.lengthOf(0)
expect(getByRole('textbox').value).to.equal(props.value)
expect(combo.tagName).to.eq('INPUT')
expect(combo.value).to.equal(props.value)
expect(() => getByRole('listbox', {hidden: true})).to.not.throw()
expect(() =>
getAllByRole('option', {
Expand All @@ -218,11 +215,11 @@ describe(json.name, () => {

// When
const {getByRole, getAllByRole} = setup(props)
const combo = getByRole('combobox')

// Then
expect(getByRole('combobox').innerHTML).to.be.a('string')
expect(getByRole('combobox').innerHTML).to.not.have.lengthOf(0)
expect(getByRole('textbox').value).to.equal(props.value)
expect(combo.tagName).to.eq('INPUT')
expect(combo.value).to.equal(props.value)
expect(() => getByRole('listbox', {hidden: true})).to.not.throw()
expect(() =>
getAllByRole('option', {
Expand Down Expand Up @@ -250,11 +247,11 @@ describe(json.name, () => {

// When
const {getByRole, getAllByRole} = setup(props)
const combo = getByRole('combobox')

// Then
expect(getByRole('combobox').innerHTML).to.be.a('string')
expect(getByRole('combobox').innerHTML).to.not.have.lengthOf(0)
expect(getByRole('textbox').value).to.equal(props.value)
expect(combo.tagName).to.eq('INPUT')
expect(combo.value).to.equal(props.value)
expect(() => getByRole('listbox', {hidden: true})).to.not.throw()
expect(() =>
getAllByRole('option', {
Expand Down Expand Up @@ -294,17 +291,17 @@ describe(json.name, () => {
// When
const {getByRole, rerender} = setup(props)
keyDownEvents.forEach(keyDownEvent => fireEvent.keyDown(getByRole('combobox'), keyDownEvent))
fireEvent.change(getByRole('textbox'), changeEvent)
fireEvent.change(getByRole('combobox'), changeEvent)

// Then
expect(getByRole('textbox').value).to.equal('')
expect(getByRole('combobox').value).to.equal('')

// And
// When

rerender(<Component {...props} />)

expect(getByRole('textbox').value).to.equal(changeEvent.target.value)
expect(getByRole('combobox').value).to.equal(changeEvent.target.value)
sinon.assert.called(spy)
})
})
Expand Down
19 changes: 18 additions & 1 deletion components/molecule/dropdownList/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const MoleculeDropdownList = forwardRef(
(
{
children,
id,
onSelect,
position = POSITIONS.BOTTOM,
alwaysRender = true,
Expand All @@ -30,6 +31,7 @@ const MoleculeDropdownList = forwardRef(
visible,
onKeyDown,
'aria-label': ariaLabel,
'aria-labelledby': ariaLabelledby,
...props
},
forwardedRef
Expand Down Expand Up @@ -94,7 +96,16 @@ const MoleculeDropdownList = forwardRef(
if (!visible && !alwaysRender) return null

return (
<ul ref={ref} tabIndex={0} onKeyDown={handleKeyDown} className={classNames} role="listbox" aria-label={ariaLabel}>
<ul
id={id}
ref={ref}
tabIndex={0}
onKeyDown={handleKeyDown}
className={classNames}
role="listbox"
aria-label={ariaLabel}
aria-labelledby={ariaLabelledby}
>
{Children.toArray(children)
.filter(Boolean)
.map((child, index) => (
Expand All @@ -110,12 +121,18 @@ const MoleculeDropdownList = forwardRef(
MoleculeDropdownList.displayName = 'MoleculeDropdownList'

MoleculeDropdownList.propTypes = {
/** HTML id attribute */
id: PropTypes.string,

/** No matter if is visible or invisible, render always the content */
alwaysRender: PropTypes.bool,

/** aria-label for accessibility */
'aria-label': PropTypes.string,

/** aria-labelledby for accessibility */
'aria-labelledby': PropTypes.string,

/** Content to be included in the list (MoleculeDropdownOption) */
children: PropTypes.node,

Expand Down
Loading