Skip to content

Commit

Permalink
fix(Dropdown): fix empty data entry handling
Browse files Browse the repository at this point in the history
  • Loading branch information
tujoworker committed Feb 24, 2022
1 parent 58a7f7c commit 4e4762b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -935,6 +935,21 @@ describe('Dropdown component', () => {
).toBe(title)
})

it('should support empty data entry', () => {
const Comp = mount(<Component data={['']} />)

keydown(Comp, 32) // space

expect(
Comp.find('button').instance().getAttribute('aria-expanded')
).toBe('true')
expect(
Comp.find('.dnb-drawer-list__option')
.find('.dnb-drawer-list__option__inner')
.instance().innerHTML
).toBe('')
})

it('has a correct value content if we send in a React component', () => {
const aStringOf = 'Custom content 123'
const Comp1 = mount(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ const ItemContent = ({ hash, children }) => {
{children.render ? children.render(item, hash + n) : item}
</span>
))
} else if (children.content) {
} else if (Object.prototype.hasOwnProperty.call(children, 'content')) {
return children.render
? children.render(children.content, hash, children)
: children.content
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ export const normalizeData = (props) => {
item = { content: item, __isTransformed: true }
}

return typeof item.__id !== 'undefined' ? item : { ...item, __id }
return typeof item?.__id !== 'undefined' ? item : { ...item, __id }
})
}

Expand Down

0 comments on commit 4e4762b

Please sign in to comment.