Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Search): noResultsMessage prop can be a node #1683

Merged
merged 3 commits into from
May 22, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 4 additions & 1 deletion src/modules/Search/Search.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ export default class Search extends Component {
noResultsDescription: PropTypes.string,

/** Message to display when there are no results. */
noResultsMessage: PropTypes.string,
noResultsMessage: PropTypes.oneOfType([
PropTypes.node,
PropTypes.object,
]),
Copy link
Member

Choose a reason for hiding this comment

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

I believe this should just be PropTypes.node only. PropTypes.node includes any renderable value: string, number, element, or an array (or fragment) of any of these. However, objects are not renderable.

Let's also update the typings in Search.d.ts to reflect the type change as well.

Copy link
Contributor Author

@b0gok b0gok May 18, 2017

Choose a reason for hiding this comment

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

PropTypes.node includes any renderable value: string, number, element, or an array (or fragment) of any of these.

Didn't know about it. Thanks for useful information.
Made the necessary changes.


/** Controls whether or not the results menu is displayed. */
open: PropTypes.bool,
Expand Down
9 changes: 8 additions & 1 deletion test/specs/modules/Search/Search-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -696,13 +696,20 @@ describe('Search', () => {
.find('.message.empty .header')
.should.have.text('No results found.')
})
it('uses custom noResultsMessage', () => {
it('uses custom string for noResultsMessage', () => {
wrapperMount(<Search results={[]} minCharacters={0} noResultsMessage='Something custom' />)

wrapper
.find('.message.empty .header')
.should.have.text('Something custom')
})
it('uses custom component for noResultsMessage', () => {
wrapperMount(<Search results={[]} minCharacters={0} noResultsMessage={<span>Test</span>} />)

wrapper
.find('.message.empty .header')
.should.contain.descendants('span')
})
it('uses custom noResultsDescription if present', () => {
wrapperMount(<Search results={[]} minCharacters={0} noResultsDescription='Something custom' />)

Expand Down