Skip to content

Commit 2a758ee

Browse files
committed
feat: Support disabled/readOnly states ✨ (#200)
* fix: Show cursor in Edge, IE 11 properly * feat: Support readOnly state * chore: Fix lint errors * docs: Add documentation for form states * chore: Use action's id if available, otherwise fall back to array index * test: Add tests for actions * test: Updated snapshots
1 parent a080500 commit 2a758ee

File tree

24 files changed

+182
-75
lines changed

24 files changed

+182
-75
lines changed

README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ A lightweight and fast control to render a select component that can display hie
4949
- [simpleSelect](#simpleselect)
5050
- [showPartiallySelected](#showpartiallyselected)
5151
- [showDropdown](#showDropdown)
52+
- [form states (disabled|readOnly)](#formstates)
5253
- [Styling and Customization](#styling-and-customization)
5354
- [Using default styles](#default-styles)
5455
- [Customizing with Bootstrap, Material Design styles](#customizing-styles)
@@ -101,7 +102,7 @@ You can import the standalone UMD build from a CDN such as:
101102

102103
```html
103104
<script src="https://unpkg.com/react-dropdown-tree-select/dist/react-dropdown-tree-select.js"></script>
104-
<link href="https://unpkg.com/react-dropdown-tree-select/dist/styles.css" rel="stylesheet">
105+
<link href="https://unpkg.com/react-dropdown-tree-select/dist/styles.css" rel="stylesheet" />
105106
```
106107

107108
**Note:** Above example will always fetch the latest version. To fetch a specific version, use `https://unpkg.com/react-dropdown-tree-select@<version>/dist/...`
@@ -292,6 +293,13 @@ Type: `bool` (default: `false`)
292293

293294
If set to true, shows the dropdown when rendered. This can be used to render the component with the dropdown open as its initial state.
294295

296+
### form states (disabled|readOnly)
297+
298+
Type: `bool` (default: `false`)
299+
300+
`disabled=true` disables the dropdown completely. This is useful during form submit events.
301+
`readOnly=true` makes the dropdown read only, which means that the user can still interact with it but cannot change any of its values. This can be useful for display only forms.
302+
295303
## Styling and Customization
296304

297305
### Default styles
@@ -327,7 +335,7 @@ module: {
327335
You can import and place a style link directly by referencing it from a CDN.
328336

329337
```html
330-
<link href="https://unpkg.com/react-dropdown-tree-select/dist/styles.css" rel="stylesheet">
338+
<link href="https://unpkg.com/react-dropdown-tree-select/dist/styles.css" rel="stylesheet" />
331339
```
332340

333341
Note: Above example will always fetch the latest version. To fetch a specific version, use `https://unpkg.com/react-dropdown-tree-select@<version>/dist/styles.css`. Visit [unpkg.com](https://unpkg.com/#/) to see other options.
@@ -470,6 +478,7 @@ Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds
470478
| :---: | :---: | :---: | :---: | :---: | :---: | :---: |
471479
| [<img src="https://avatars1.githubusercontent.com/u/13344028?v=4" width="100px;"/><br /><sub><b>BaarishRain</b></sub>](https://github.com/BaarishRain)<br />[🐛](https://github.com/dowjones/react-dropdown-tree-select/issues?q=author%3ABaarishRain "Bug reports") | [<img src="https://avatars0.githubusercontent.com/u/32507174?v=4" width="100px;"/><br /><sub><b>Kovacs Alexandru Robert</b></sub>](http://kovacsalexandrurobert.ro)<br />[🤔](#ideas-akovacspentalog "Ideas, Planning, & Feedback") | [<img src="https://avatars2.githubusercontent.com/u/11201133?v=4" width="100px;"/><br /><sub><b>Alexis Mondragon</b></sub>](https://github.com/amondragon)<br />[🤔](#ideas-amondragon "Ideas, Planning, & Feedback") | [<img src="https://avatars2.githubusercontent.com/u/13438795?v=4" width="100px;"/><br /><sub><b>Charlie91</b></sub>](https://github.com/Charlie91)<br />[🐛](https://github.com/dowjones/react-dropdown-tree-select/issues?q=author%3ACharlie91 "Bug reports") | [<img src="https://avatars3.githubusercontent.com/u/1930681?v=4" width="100px;"/><br /><sub><b>Dhirendrasinh</b></sub>](https://github.com/dhirendrarathod2000)<br />[🐛](https://github.com/dowjones/react-dropdown-tree-select/issues?q=author%3Adhirendrarathod2000 "Bug reports") | [<img src="https://avatars1.githubusercontent.com/u/7006862?v=4" width="100px;"/><br /><sub><b>JKapostins</b></sub>](https://github.com/JKapostins)<br />[🐛](https://github.com/dowjones/react-dropdown-tree-select/issues?q=author%3AJKapostins "Bug reports") | [<img src="https://avatars0.githubusercontent.com/u/24354568?v=4" width="100px;"/><br /><sub><b>josvegit</b></sub>](https://github.com/josvegit)<br />[🐛](https://github.com/dowjones/react-dropdown-tree-select/issues?q=author%3Ajosvegit "Bug reports") |
472480
| [<img src="https://avatars1.githubusercontent.com/u/12422912?v=4" width="100px;"/><br /><sub><b>Luis Locon</b></sub>](https://twitter.com/LoconLuis)<br />[🐛](https://github.com/dowjones/react-dropdown-tree-select/issues?q=author%3Aloconluis "Bug reports") | [<img src="https://avatars3.githubusercontent.com/u/10121255?v=4" width="100px;"/><br /><sub><b>Mikdat DOĞRU</b></sub>](https://github.com/mikdatdogru)<br />[🐛](https://github.com/dowjones/react-dropdown-tree-select/issues?q=author%3Amikdatdogru "Bug reports") | [<img src="https://avatars1.githubusercontent.com/u/7553535?v=4" width="100px;"/><br /><sub><b>Will Izard</b></sub>](https://github.com/will-izard)<br />[🤔](#ideas-will-izard "Ideas, Planning, & Feedback") | [<img src="https://avatars3.githubusercontent.com/u/4504265?v=4" width="100px;"/><br /><sub><b>Nikola Peric</b></sub>](https://gitlab.com/nikperic)<br />[🐛](https://github.com/dowjones/react-dropdown-tree-select/issues?q=author%3Anikolap "Bug reports") | [<img src="https://avatars2.githubusercontent.com/u/6119839?v=4" width="100px;"/><br /><sub><b>Ramón Alejandro Reyes Fajardo</b></sub>](https://github.com/ramonrf)<br />[🐛](https://github.com/dowjones/react-dropdown-tree-select/issues?q=author%3Aramonrf "Bug reports") | [<img src="https://avatars3.githubusercontent.com/u/10716099?v=4" width="100px;"/><br /><sub><b>Sarada Cherukupalli</b></sub>](https://github.com/sarada-Cheukupalli)<br />[🤔](#ideas-sarada-Cheukupalli "Ideas, Planning, & Feedback") | [<img src="https://avatars1.githubusercontent.com/u/45608461?v=4" width="100px;"/><br /><sub><b>Dilip Gavara</b></sub>](https://github.com/dilip025)<br />[💻](https://github.com/dowjones/react-dropdown-tree-select/commits?author=dilip025 "Code") |
481+
473482
<!-- ALL-CONTRIBUTORS-LIST:END -->
474483

475484
This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind welcome!

__snapshots__/src/index.test.js.md

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

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

7+
## doesn't toggle dropdown if it's disabled
8+
9+
> Snapshot 1
10+
11+
<div
12+
className="react-dropdown-tree-select"
13+
>
14+
<div
15+
className="dropdown"
16+
>
17+
<a
18+
className="dropdown-trigger arrow disabled bottom"
19+
onClick={false}
20+
>
21+
<Input
22+
disabled={true}
23+
inputRef={Function inputRef {}}
24+
onBlur={Function {}}
25+
onFocus={Function {}}
26+
onInputChange={Function {}}
27+
onTagRemove={Function {}}
28+
tags={[]}
29+
/>
30+
</a>
31+
</div>
32+
</div>
33+
734
## renders default state
835

936
> Snapshot 1
@@ -261,31 +288,4 @@ Generated by [AVA](https://ava.li).
261288
/>
262289
</div>
263290
</div>
264-
</div
265-
266-
## doesn't toggle dropdown if it's disabled
267-
268-
> Snapshot 1
269-
270-
<div
271-
className="react-dropdown-tree-select"
272-
>
273-
<div
274-
className="dropdown"
275-
>
276-
<a
277-
className="dropdown-trigger arrow disabled bottom"
278-
onClick={false}
279-
>
280-
<Input
281-
disabled={true}
282-
inputRef={Function inputRef {}}
283-
onBlur={Function {}}
284-
onFocus={Function {}}
285-
onInputChange={Function {}}
286-
onTagRemove={Function {}}
287-
tags={[]}
288-
/>
289-
</a>
290-
</div>
291-
</div>
291+
</div>
0 Bytes
Binary file not shown.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ Generated by [AVA](https://ava.li).
107107
type="text"
108108
/>
109109
</li>
110-
</ul
110+
</ul>
111111

112112
## should render disabled input
113113

@@ -127,4 +127,4 @@ Generated by [AVA](https://ava.li).
127127
type="text"
128128
/>
129129
</li>
130-
</ul>
130+
</ul>
0 Bytes
Binary file not shown.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Snapshot report for `src\tree-node\actions.test.js`
2+
3+
The actual snapshot is saved in `actions.test.js.snap`.
4+
5+
Generated by [AVA](https://ava.li).
6+
7+
## renders actions
8+
9+
> Snapshot 1
10+
11+
[
12+
<Action
13+
actionData={
14+
{
15+
action: 'action-0',
16+
id: undefined,
17+
}
18+
}
19+
className="cn0-0-0"
20+
junk="1"
21+
key="action-0"
22+
onAction={Function onAction {}}
23+
text="hello"
24+
title="action"
25+
/>,
26+
]
27+
28+
## returns null if actions are empty
29+
30+
> Snapshot 1
31+
32+
''
33+
34+
> Snapshot 2
35+
36+
''
415 Bytes
Binary file not shown.

__snapshots__/src/tree-node/index.test.js.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,5 @@ Generated by [AVA](https://ava.li).
3636
]
3737
}
3838
id="0-0-0"
39-
onAction={Function onAction {}}
4039
/>
4140
</li>
-37 Bytes
Binary file not shown.

docs/bundle.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)