Skip to content

Commit 7fd83e4

Browse files
rohanravRohan Ravindranlayershifter
authored
feat(Search): add "placeholder" & documentation (#4282)
* docs: add search placeholder API documentation * Update docs/src/examples/modules/Search/Types/SearchExampleStandard.js * add a unit test Co-authored-by: Rohan Ravindran <[email protected]> Co-authored-by: Oleksandr Fediashov <[email protected]> Co-authored-by: Oleksandr Fediashov <[email protected]>
1 parent 9042580 commit 7fd83e4

File tree

4 files changed

+18
-2
lines changed

4 files changed

+18
-2
lines changed

docs/src/examples/modules/Search/Types/SearchExampleStandard.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ function SearchExampleStandard() {
6767
<Grid.Column width={6}>
6868
<Search
6969
loading={loading}
70+
placeholder='Search...'
7071
onResultSelect={(e, data) =>
7172
dispatch({ type: 'UPDATE_SELECTION', selection: data.result.title })
7273
}

src/modules/Search/Search.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@ export interface StrictSearchProps {
159159

160160
/** A search can have different sizes. */
161161
size?: 'mini' | 'tiny' | 'small' | 'large' | 'big' | 'huge' | 'massive'
162+
163+
/** A search can show placeholder text when empty. */
164+
placeholder?: string
162165
}
163166

164167
export interface SearchResultData extends SearchProps {

src/modules/Search/Search.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ export default class Search extends Component {
369369
// ----------------------------------------
370370

371371
renderSearchInput = (rest) => {
372-
const { icon, input } = this.props
372+
const { icon, input, placeholder } = this.props
373373
const { value } = this.state
374374

375375
return Input.create(input, {
@@ -382,6 +382,7 @@ export default class Search extends Component {
382382
onClick: this.handleInputClick,
383383
tabIndex: '0',
384384
value,
385+
placeholder,
385386
},
386387
// Nested shorthand props need special treatment to survive the shallow merge
387388
overrideProps: overrideSearchInputProps,
@@ -666,6 +667,9 @@ Search.propTypes = {
666667

667668
/** A search can have different sizes. */
668669
size: PropTypes.oneOf(_.without(SUI.SIZES, 'medium')),
670+
671+
/** A search can show placeholder text when empty. */
672+
placeholder: PropTypes.string,
669673
}
670674

671675
Search.defaultProps = {
@@ -674,6 +678,7 @@ Search.defaultProps = {
674678
minCharacters: 1,
675679
noResultsMessage: 'No results found.',
676680
showNoResults: true,
681+
placeholder: '',
677682
}
678683

679684
Search.autoControlledProps = ['open', 'value']

test/specs/modules/Search/Search-test.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,7 @@ describe('Search', () => {
743743
})
744744

745745
it(`will not merge for a function`, () => {
746-
// TODO: V3 remove this test and simplify the implementation
746+
// TODO: V4 remove this test and simplify the implementation
747747
consoleUtil.disableOnce()
748748

749749
wrapperMount(<Search input={{ input: (Component, props) => <Component {...props} /> }} />)
@@ -752,6 +752,13 @@ describe('Search', () => {
752752
input.should.have.prop('autoComplete', 'off')
753753
input.should.have.not.className('prompt')
754754
})
755+
756+
it(`"placeholder" in passed to an "input"`, () => {
757+
wrapperMount(<Search placeholder="foo" />)
758+
const input = wrapper.find('input')
759+
760+
input.should.have.prop('placeholder', 'foo')
761+
})
755762
})
756763

757764
describe('input props', () => {

0 commit comments

Comments
 (0)