Skip to content

Commit 4256ce2

Browse files
committed
fix: Bundle text props
1 parent a4fc033 commit 4256ce2

File tree

10 files changed

+57
-62
lines changed

10 files changed

+57
-62
lines changed

README.md

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,14 @@ A lightweight and fast control to render a select component that can display hie
4545
- [onChange](#onchange)
4646
- [onNodeToggle](#onnodetoggle)
4747
- [data](#data)
48-
- [placeholderText](#placeholdertext)
49-
- [noMatchesText](#nomatchestext)
48+
- [texts](#texts)
5049
- [keepTreeOnSearch](#keeptreeonsearch)
5150
- [keepChildrenOnSearch](#keepchildrenonsearch)
5251
- [simpleSelect](#simpleselect)
5352
- [showPartiallySelected](#showpartiallyselected)
5453
- [showDropdown](#showDropdown)
5554
- [form states (disabled|readOnly)](#formstates)
5655
- [id](#id)
57-
- [label](#label)
58-
- [labelRemove](#labelRemove)
5956
- [Styling and Customization](#styling-and-customization)
6057
- [Using default styles](#default-styles)
6158
- [Customizing with Bootstrap, Material Design styles](#customizing-styles)
@@ -280,17 +277,20 @@ The `action` object requires the following structure:
280277

281278
An array renders a tree with multiple root level items whereas an object renders a tree with a single root element (e.g. a `Select All` root node).
282279

283-
### placeholderText
280+
### texts
284281

285-
Type: `string`
286-
287-
The text to display as placeholder on the search box. Defaults to `Choose...`
282+
Texts to override output for
288283

289-
### noMatchesText
290-
291-
Type: `string`
284+
The `texts` object requires the following structure:
292285

293-
The text to display when the search does not find results in the content list. Defaults to `No matches found`
286+
```js
287+
{
288+
placeholder, // optional: The text to display as placeholder on the search box. Defaults to `Choose...`
289+
noMatches, // optional: The text to display when the search does not find results in the content list. Defaults to `No matches found`
290+
label, // optional: Adds `aria-labelledby` to search input when input starts with `#`, adds `aria-label` to search input when label has value (not containing '#')
291+
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`
292+
}
293+
```
294294

295295
### keepTreeOnSearch
296296

@@ -339,18 +339,6 @@ Specific id for container. The container renders with a default id of `rdtsN` wh
339339

340340
Use to ensure a own unique id when a simple counter is not sufficient, e.g in a partial server render (SSR)
341341

342-
### label
343-
344-
Type: `string`
345-
346-
Adds `aria-labelledby` to search input when input starts with `#`, adds `aria-label` to search input when label has value (not containing '#')
347-
348-
### labelRemove
349-
350-
Type: `string`
351-
352-
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`
353-
354342
## Styling and Customization
355343

356344
### Default styles
@@ -443,10 +431,10 @@ Node toggling also achieves the expand/collapse effect by manipulating css class
443431

444432
### How do I change the placeholder text?
445433

446-
The default [placeholder](#placeholdertext) is `Choose...`. If you want to change this to something else, you can use `placeholderText` property to set it.
434+
The default [placeholder](#texts) is `Choose...`. If you want to change this to something else, you can use `placeholder` property to set it.
447435

448436
```jsx
449-
<DropdownTreeSelect placeholderText="Search" />
437+
<DropdownTreeSelect texts={{ placeholder: 'Search' }} />
450438
```
451439

452440
### How do I tweak styles?

__snapshots__/src/index.test.js.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Generated by [AVA](https://ava.li).
2727
onKeyDown={Function {}}
2828
onTagRemove={Function {}}
2929
tags={[]}
30+
texts={{}}
3031
/>
3132
</a>
3233
</div>
@@ -103,6 +104,7 @@ Generated by [AVA](https://ava.li).
103104
onBlur={Function onBlur {}}
104105
onChange={Function onChange {}}
105106
onFocus={Function onFocus {}}
107+
texts={{}}
106108
>
107109
<div
108110
className="react-dropdown-tree-select"
@@ -123,6 +125,7 @@ Generated by [AVA](https://ava.li).
123125
onKeyDown={Function {}}
124126
onTagRemove={Function {}}
125127
tags={[]}
128+
texts={{}}
126129
>
127130
<ul
128131
className="tag-list"
@@ -171,6 +174,7 @@ Generated by [AVA](https://ava.li).
171174
onKeyDown={Function {}}
172175
onTagRemove={Function {}}
173176
tags={[]}
177+
texts={{}}
174178
/>
175179
</a>
176180
<div
45 Bytes
Binary file not shown.

docs/guides/migrating-from-1-to-2.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ We've made some changes in the component between the versions which is covered i
44

55
### Property changes
66

7-
| Description | Usage before | Usage after |
8-
| ------------------------------------------------------------------------ | -------------------------------------- | --------------------- |
9-
| Added a new radio select mode<br>Selection is done in a shared mode-prop | `simpleSelect={true}` / `simpleSelect` | `mode='simpleSelect'` |
7+
| Description | Usage before | Usage after |
8+
| ------------------------------------------------------------------------ | ----------------------------------------------------------- | ------------------------------------------------------------- |
9+
| Added a new radio select mode<br>Selection is done in a shared mode-prop | `simpleSelect={true}` / `simpleSelect` | `mode='simpleSelect'` |
10+
| Bundled text props into a single object | `placeholderText='My text'`<br>`noMatchesText='No matches'` | `texts={{ placeholder: 'My text', noMatches: 'No matches' }}` |

src/a11y/a11y.test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ test('regular tree has no a11y exceptions', async t => {
4848
const { tree } = t.context
4949
const component = mountToDoc(
5050
<div>
51-
<DropdownTreeSelect data={tree} showDropDown label="test" />
52-
<DropdownTreeSelect data={tree} showDropDown disabled label="test" />
53-
<DropdownTreeSelect data={tree} showDropDown readOnly label="test" />
54-
<DropdownTreeSelect data={tree} showDropDown simpleSelect label="test" />
55-
<DropdownTreeSelect data={tree} showDropDown simpleSelect label="test" />
51+
<DropdownTreeSelect data={tree} showDropDown texts={{ label: 'test' }} />
52+
<DropdownTreeSelect data={tree} showDropDown disabled texts={{ label: 'test' }} />
53+
<DropdownTreeSelect data={tree} showDropDown readOnly texts={{ label: 'test' }} />
54+
<DropdownTreeSelect data={tree} showDropDown simpleSelect texts={{ label: 'test' }} />
55+
<DropdownTreeSelect data={tree} showDropDown simpleSelect texts={{ label: 'test' }} />
5656
</div>
5757
)
5858
const domNode = component.getDOMNode()

src/index.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,12 @@ class DropdownTreeSelect extends Component {
2727
clearSearchOnChange: PropTypes.bool,
2828
keepTreeOnSearch: PropTypes.bool,
2929
keepChildrenOnSearch: PropTypes.bool,
30-
placeholderText: PropTypes.string,
30+
texts: PropTypes.shape({
31+
placeholder: PropTypes.string,
32+
noMatches: PropTypes.string,
33+
label: PropTypes.string,
34+
labelRemove: PropTypes.string,
35+
}),
3136
showDropdown: PropTypes.bool,
3237
className: PropTypes.string,
3338
onChange: PropTypes.func,
@@ -36,20 +41,18 @@ class DropdownTreeSelect extends Component {
3641
onFocus: PropTypes.func,
3742
onBlur: PropTypes.func,
3843
simpleSelect: PropTypes.bool,
39-
noMatchesText: PropTypes.string,
4044
showPartiallySelected: PropTypes.bool,
4145
disabled: PropTypes.bool,
4246
readOnly: PropTypes.bool,
4347
hierarchical: PropTypes.bool,
4448
id: PropTypes.string,
45-
label: PropTypes.string,
46-
labelRemove: PropTypes.string,
4749
}
4850

4951
static defaultProps = {
5052
onFocus: () => {},
5153
onBlur: () => {},
5254
onChange: () => {},
55+
texts: {},
5356
}
5457

5558
constructor(props) {
@@ -288,7 +291,7 @@ class DropdownTreeSelect extends Component {
288291
this.searchInput = el
289292
}}
290293
tags={this.state.tags}
291-
placeholderText={this.props.placeholderText}
294+
texts={this.props.texts}
292295
onInputChange={this.onInputChange}
293296
onFocus={this.onInputFocus}
294297
onBlur={this.onInputBlur}
@@ -297,14 +300,12 @@ class DropdownTreeSelect extends Component {
297300
disabled={this.props.disabled}
298301
readOnly={this.props.readOnly}
299302
activeDescendant={activeDescendant}
300-
label={this.props.label}
301-
labelRemove={this.props.labelRemove}
302303
/>
303304
</a>
304305
{this.state.showDropdown && (
305306
<div className={cx('dropdown-content')}>
306307
{this.state.allNodesHidden ? (
307-
<span className="no-matches">{this.props.noMatchesText || 'No matches found'}</span>
308+
<span className="no-matches">{this.props.texts.noMatches || 'No matches found'}</span>
308309
) : (
309310
<Tree
310311
data={this.state.tree}

src/index.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,14 +221,14 @@ test('detects click outside when other dropdown instance', t => {
221221

222222
test('adds aria-labelledby when label contains # to search input', t => {
223223
const { tree } = t.context
224-
const wrapper = mount(<DropdownTreeSelect data={tree} label="#hello #world" />)
224+
const wrapper = mount(<DropdownTreeSelect data={tree} texts={{ label: '#hello #world' }} />)
225225
t.deepEqual(wrapper.find('.search').prop('aria-labelledby'), 'hello world')
226226
t.deepEqual(wrapper.find('.search').prop('aria-label'), undefined)
227227
})
228228

229229
test('adds aria-label when having label on search input', t => {
230230
const { tree } = t.context
231-
const wrapper = mount(<DropdownTreeSelect data={tree} label="hello world" />)
231+
const wrapper = mount(<DropdownTreeSelect data={tree} texts={{ label: 'hello world' }} />)
232232
t.deepEqual(wrapper.find('.search').prop('aria-labelledby'), undefined)
233233
t.deepEqual(wrapper.find('.search').prop('aria-label'), 'hello world')
234234
})

src/input/index.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const getTags = (tags = [], onDelete, readOnly, disabled, labelRemove) =>
2828
class Input extends PureComponent {
2929
static propTypes = {
3030
tags: PropTypes.array,
31-
placeholderText: PropTypes.string,
31+
texts: PropTypes.object,
3232
onInputChange: PropTypes.func,
3333
onFocus: PropTypes.func,
3434
onBlur: PropTypes.func,
@@ -38,8 +38,6 @@ class Input extends PureComponent {
3838
disabled: PropTypes.bool,
3939
readOnly: PropTypes.bool,
4040
activeDescendant: PropTypes.string,
41-
label: PropTypes.string,
42-
labelRemove: PropTypes.string,
4341
}
4442

4543
constructor(props) {
@@ -57,35 +55,33 @@ class Input extends PureComponent {
5755
tags,
5856
onTagRemove,
5957
inputRef,
60-
placeholderText = 'Choose...',
58+
texts = {},
6159
onFocus,
6260
onBlur,
6361
disabled,
6462
readOnly,
6563
onKeyDown,
6664
activeDescendant,
67-
label,
68-
labelRemove,
6965
} = this.props
7066

7167
return (
7268
<ul className={cx('tag-list')}>
73-
{getTags(tags, onTagRemove, readOnly, disabled, labelRemove)}
69+
{getTags(tags, onTagRemove, readOnly, disabled, texts.labelRemove)}
7470
<li className={cx('tag-item')}>
7571
<input
7672
type="text"
7773
disabled={disabled}
7874
ref={inputRef}
7975
className={cx('search')}
80-
placeholder={placeholderText}
76+
placeholder={texts.placeholder || 'Choose...'}
8177
onKeyDown={onKeyDown}
8278
onChange={this.handleInputChange}
8379
onFocus={onFocus}
8480
onBlur={onBlur}
8581
readOnly={readOnly}
8682
aria-activedescendant={activeDescendant}
8783
aria-autocomplete={onKeyDown ? 'list' : undefined}
88-
{...getAriaLabel(label)}
84+
{...getAriaLabel(texts.label)}
8985
/>
9086
</li>
9187
</ul>

src/input/index.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ test('renders input when no tags are passed', t => {
1919

2020
test('renders placeholder', t => {
2121
const placeholderText = 'select something'
22-
const wrapper = toJson(shallow(<Input placeholderText={placeholderText} />))
22+
const wrapper = toJson(shallow(<Input texts={{ placeholder: placeholderText }} />))
2323
t.snapshot(wrapper)
2424
})
2525

types/react-dropdown-tree-select.d.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ declare module "react-dropdown-tree-select" {
1515
* NOTE this works only in combination with keepTreeOnSearch
1616
*/
1717
keepChildrenOnSearch?: boolean;
18-
/** The text to display as placeholder on the search box. Defaults to Choose... */
19-
placeholderText?: string;
18+
/** Texts to override output for */
19+
texts?: TextProps;
2020
/** If set to true, shows the dropdown when rendered.
2121
* This can be used to render the component with the dropdown open as its initial state
2222
*/
@@ -51,8 +51,6 @@ declare module "react-dropdown-tree-select" {
5151
* Defaults to false
5252
*/
5353
simpleSelect?: boolean;
54-
/** The text to display when the search does not find results in the content list. Defaults to No matches found */
55-
noMatchesText?: string;
5654
/** If set to true, shows checkboxes in a partial state when one, but not all of their children are selected.
5755
* Allows styling of partially selected nodes as well, by using :indeterminate pseudo class.
5856
* Simply add desired styles to .node.partial .checkbox-item:indeterminate { ... } in your CSS
@@ -70,10 +68,6 @@ declare module "react-dropdown-tree-select" {
7068
* Use to ensure a own unique id when a simple counter is not sufficient, e.g in a partial server render (SSR)
7169
*/
7270
id?: string;
73-
/** Adds `aria-labelledby` to search input when input starts with `#`, adds `aria-label` to search input when label has value (not containing '#') */
74-
label?: string;
75-
/** 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 */
76-
labelRemove?: string;
7771
}
7872

7973
export interface DropdownTreeSelectState {
@@ -126,6 +120,17 @@ declare module "react-dropdown-tree-select" {
126120
children?: TreeNode[];
127121
}
128122

123+
export interface TextProps {
124+
/** The text to display as placeholder on the search box. Defaults to Choose... */
125+
placeholderT: string;
126+
/** The text to display when the search does not find results in the content list. Defaults to No matches found */
127+
noMatches: string;
128+
/** Adds `aria-labelledby` to search input when input starts with `#`, adds `aria-label` to search input when label has value (not containing '#') */
129+
label?: string;
130+
/** 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 */
131+
labelRemove?: string;
132+
}
133+
129134
export interface NodeAction {
130135
/** CSS class for the node. e.g. `fa fa-info` */
131136
className: string;

0 commit comments

Comments
 (0)