Skip to content

Commit dd2dbbc

Browse files
ldevebermrchief
andauthored
feat: Support placeholder for inline search input (#404)
Co-authored-by: Hrusikesh Panda <mrchief@users.noreply.github.com>
1 parent 0b8d9b7 commit dd2dbbc

File tree

9 files changed

+70
-7
lines changed

9 files changed

+70
-7
lines changed

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -299,10 +299,11 @@ The `texts` object requires the following structure:
299299

300300
```js
301301
{
302-
placeholder, // optional: The text to display as placeholder on the search box. Defaults to `Choose...`
303-
noMatches, // optional: The text to display when the search does not find results in the content list. Defaults to `No matches found`
304-
label, // optional: Adds `aria-labelledby` to search input when input starts with `#`, adds `aria-label` to search input when label has value (not containing '#')
305-
labelRemove, // optional: The text to display for `aria-label` on tag delete buttons which is combined with `aria-labelledby` pointing to the node label. Defaults to `Remove`
302+
placeholder, // optional: The text to display as placeholder on the search box. Defaults to `Choose...`
303+
inlineSearchPlaceholder, // optional: The text to display as placeholder on the inline search box. Only applicable with the `inlineSearchInput` setting. Defaults to `Search...`
304+
noMatches, // optional: The text to display when the search does not find results in the content list. Defaults to `No matches found`
305+
label, // optional: Adds `aria-labelledby` to search input when input starts with `#`, adds `aria-label` to search input when label has value (not containing '#')
306+
labelRemove, // optional: The text to display for `aria-label` on tag delete buttons which is combined with `aria-labelledby` pointing to the node label. Defaults to `Remove`
306307
}
307308
```
308309

@@ -592,6 +593,7 @@ Released 2017 by [Hrusikesh Panda](https://github.com/mrchief) @ [Dow Jones](htt
592593
Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)):
593594

594595
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
596+
595597
<!-- prettier-ignore -->
596598
| [<img src="https://avatars0.githubusercontent.com/u/966550?v=4" width="100px;" alt="toofff"/><br /><sub><b>toofff</b></sub>](http://www.yanoucrea.fr)<br />[🐛](https://github.com/dowjones/react-dropdown-tree-select/issues?q=author%3Atoofff "Bug reports") [💻](https://github.com/dowjones/react-dropdown-tree-select/commits?author=toofff "Code") [📖](https://github.com/dowjones/react-dropdown-tree-select/commits?author=toofff "Documentation") [🤔](#ideas-toofff "Ideas, Planning, & Feedback") | [<img src="https://avatars3.githubusercontent.com/u/1257968?v=4" width="100px;" alt="Grégory Copin"/><br /><sub><b>Grégory Copin</b></sub>](http://www.les-tilleuls.coop)<br />[🐛](https://github.com/dowjones/react-dropdown-tree-select/issues?q=author%3AGregcop1 "Bug reports") [💻](https://github.com/dowjones/react-dropdown-tree-select/commits?author=Gregcop1 "Code") | [<img src="https://avatars1.githubusercontent.com/u/7589718?v=4" width="100px;" alt="PRIYANSHU AGRAWAL"/><br /><sub><b>PRIYANSHU AGRAWAL</b></sub>](https://github.com/priyanshu92)<br />[🐛](https://github.com/dowjones/react-dropdown-tree-select/issues?q=author%3Apriyanshu92 "Bug reports") [💻](https://github.com/dowjones/react-dropdown-tree-select/commits?author=priyanshu92 "Code") [🤔](#ideas-priyanshu92 "Ideas, Planning, & Feedback") | [<img src="https://avatars3.githubusercontent.com/u/425261?v=4" width="100px;" alt="James Greenaway"/><br /><sub><b>James Greenaway</b></sub>](http://james.greenaway.io)<br />[🐛](https://github.com/dowjones/react-dropdown-tree-select/issues?q=author%3Ajvgreenaway "Bug reports") [💻](https://github.com/dowjones/react-dropdown-tree-select/commits?author=jvgreenaway "Code") [🤔](#ideas-jvgreenaway "Ideas, Planning, & Feedback") | [<img src="https://avatars1.githubusercontent.com/u/36223986?v=4" width="100px;" alt="itrombitas"/><br /><sub><b>itrombitas</b></sub>](https://github.com/itrombitas)<br />[💻](https://github.com/dowjones/react-dropdown-tree-select/commits?author=itrombitas "Code") | [<img src="https://avatars2.githubusercontent.com/u/18341459?v=4" width="100px;" alt="Dave Henton"/><br /><sub><b>Dave Henton</b></sub>](https://github.com/davehenton)<br />[🚇](#infra-davehenton "Infrastructure (Hosting, Build-Tools, etc)") | [<img src="https://avatars3.githubusercontent.com/u/4869717?v=4" width="100px;" alt="Swetha Kolli"/><br /><sub><b>Swetha Kolli</b></sub>](https://github.com/nagaskolli)<br />[💻](https://github.com/dowjones/react-dropdown-tree-select/commits?author=nagaskolli "Code") |
597599
| :---: | :---: | :---: | :---: | :---: | :---: | :---: |

__snapshots__/src/index.test.js.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Generated by [AVA](https://ava.li).
3030
>
3131
<Input
3232
clientId="rdts"
33+
inlineSearchInput={false}
3334
inputRef={Function inputRef {}}
3435
onBlur={Function {}}
3536
onFocus={Function {}}
@@ -203,6 +204,7 @@ Generated by [AVA](https://ava.li).
203204
>
204205
<Input
205206
clientId="rdts"
207+
inlineSearchInput={true}
206208
inputRef={Function inputRef {}}
207209
onBlur={Function {}}
208210
onFocus={Function {}}
@@ -370,6 +372,7 @@ Generated by [AVA](https://ava.li).
370372
<Input
371373
clientId="rdts"
372374
disabled={true}
375+
inlineSearchInput={false}
373376
inputRef={Function inputRef {}}
374377
onBlur={Function {}}
375378
onFocus={Function {}}
@@ -506,6 +509,7 @@ Generated by [AVA](https://ava.li).
506509
>
507510
<Input
508511
clientId="rdts"
512+
inlineSearchInput={false}
509513
inputRef={Function inputRef {}}
510514
mode="radioSelect"
511515
onBlur={Function {}}
@@ -655,6 +659,7 @@ Generated by [AVA](https://ava.li).
655659
>
656660
<Input
657661
clientId="rdts"
662+
inlineSearchInput={false}
658663
inputRef={Function inputRef {}}
659664
onBlur={Function {}}
660665
onFocus={Function {}}
@@ -708,6 +713,7 @@ Generated by [AVA](https://ava.li).
708713
>
709714
<Input
710715
clientId="rdts"
716+
inlineSearchInput={false}
711717
inputRef={Function inputRef {}}
712718
onBlur={Function {}}
713719
onFocus={Function {}}

__snapshots__/src/index.test.js.snap

41 Bytes
Binary file not shown.

__snapshots__/src/input/index.test.js.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@ The actual snapshot is saved in `index.test.js.snap`.
44

55
Generated by [AVA](https://ava.li).
66

7+
## renders inline search placeholder
8+
9+
> Snapshot 1
10+
11+
<input
12+
className="search"
13+
onChange={Function {}}
14+
placeholder="Search something"
15+
type="text"
16+
/>
17+
718
## renders input
819

920
> Snapshot 1
34 Bytes
Binary file not shown.

docs/src/stories/Options/index.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ class WithOptions extends PureComponent {
2020
disabled: false,
2121
readOnly: false,
2222
hierarchical: false,
23+
placeholder: 'Choose...',
24+
inlineSearchPlaceholder: 'Search...',
2325
}
2426
}
2527

@@ -48,6 +50,8 @@ class WithOptions extends PureComponent {
4850
readOnly,
4951
showDropdown,
5052
inlineSearchInput,
53+
placeholder,
54+
inlineSearchPlaceholder,
5155
} = this.state
5256

5357
return (
@@ -83,6 +87,24 @@ class WithOptions extends PureComponent {
8387
<option value="always">Always</option>
8488
</select>
8589
</div>
90+
<div style={{ marginBottom: '10px' }}>
91+
<label htmlFor="placeholder">Placeholder text: </label>
92+
<input
93+
id="placeholder"
94+
type="text"
95+
value={placeholder}
96+
onChange={e => this.setState({ placeholder: e.target.value })}
97+
/>
98+
</div>
99+
<div style={{ marginBottom: '10px' }}>
100+
<label htmlFor="inlinePlaceholderText">Inline placeholder text: </label>
101+
<input
102+
id="inlineSearchPlaceholder"
103+
type="text"
104+
value={inlineSearchPlaceholder}
105+
onChange={e => this.setState({ inlineSearchPlaceholder: e.target.value })}
106+
/>
107+
</div>
86108
<Checkbox
87109
label="Inline Search Input"
88110
value="inlineSearchInput"
@@ -132,7 +154,7 @@ class WithOptions extends PureComponent {
132154
readOnly={readOnly}
133155
inlineSearchInput={inlineSearchInput}
134156
showDropdown={showDropdown}
135-
texts={{ label: 'Demo Dropdown' }}
157+
texts={{ label: 'Demo Dropdown', placeholder, inlineSearchPlaceholder }}
136158
/>
137159
</div>
138160
</div>

src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class DropdownTreeSelect extends Component {
2929
keepOpenOnSelect: PropTypes.bool,
3030
texts: PropTypes.shape({
3131
placeholder: PropTypes.string,
32+
inlineSearchPlaceholder: PropTypes.string,
3233
noMatches: PropTypes.string,
3334
label: PropTypes.string,
3435
labelRemove: PropTypes.string,
@@ -306,6 +307,7 @@ class DropdownTreeSelect extends Component {
306307
onBlur={this.onInputBlur}
307308
onKeyDown={this.onKeyboardKeyDown}
308309
{...commonProps}
310+
inlineSearchInput={inlineSearchInput}
309311
/>
310312
)
311313
return (

src/input/index.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,27 @@ class Input extends PureComponent {
3030
}
3131

3232
render() {
33-
const { inputRef, texts = {}, onFocus, onBlur, disabled, readOnly, onKeyDown, activeDescendant } = this.props
33+
const {
34+
inputRef,
35+
texts = {},
36+
onFocus,
37+
onBlur,
38+
disabled,
39+
readOnly,
40+
onKeyDown,
41+
activeDescendant,
42+
inlineSearchInput,
43+
} = this.props
3444

3545
return (
3646
<input
3747
type="text"
3848
disabled={disabled}
3949
ref={inputRef}
4050
className="search"
41-
placeholder={texts.placeholder || 'Choose...'}
51+
placeholder={
52+
inlineSearchInput ? texts.inlineSearchPlaceholder || 'Search...' : texts.placeholder || 'Choose...'
53+
}
4254
onKeyDown={onKeyDown}
4355
onChange={this.handleInputChange}
4456
onFocus={onFocus}

src/input/index.test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ test('renders placeholder', t => {
1717
t.snapshot(wrapper)
1818
})
1919

20+
test('renders inline search placeholder', t => {
21+
const placeholderText = 'Search something'
22+
const wrapper = toJson(
23+
shallow(<Input inlineSearchInput={true} texts={{ inlineSearchPlaceholder: placeholderText }} />)
24+
)
25+
t.snapshot(wrapper)
26+
})
27+
2028
test('raises onchange', t => {
2129
const onChange = spy()
2230
const wrapper = shallow(<Input onInputChange={onChange} />)

0 commit comments

Comments
 (0)