Skip to content

Commit 424c523

Browse files
committed
feat(dropdown): Added width attribute
1 parent b9980b9 commit 424c523

File tree

3 files changed

+22
-53
lines changed

3 files changed

+22
-53
lines changed

demo/demo_app.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ render(
4646
<WSWeekPicker onChange={({year, week}) => console.log('New week selected:', week)}/>
4747
<br />
4848
<br />
49-
<WSDropdown text="Multiple" type="button" placeholder="Filter values.." filterable multiple items={[
49+
<WSDropdown text="Multiple" type="button" width="500px" placeholder="Filter values.." filterable multiple items={[
5050
'New',
5151
'New From Template',
5252
'Open',
@@ -77,7 +77,7 @@ render(
7777
'Save'
7878
]}/>
7979
<br />
80-
<WSDropdown text="Input" type="select" placeholder="tasd" value="222" inputOnly/>
80+
<WSDropdown text="Input" type="select" width="50%" placeholder="tasd" value="222" inputOnly/>
8181
<br />
8282
<WSNotification />
8383
<br />

doc/components/dropdown.md

+15-49
Original file line numberDiff line numberDiff line change
@@ -46,54 +46,33 @@ An item can be either a simple string or a object containing the following keys:
4646
- **disabled**: boolean |adds the class .is-disabled to the item
4747
- **className**: string | classes which get's added to the item</li></ul>
4848

49-
<<<<<<< HEAD
5049
**Value**:
51-
=======
52-
**Value**:
53-
>>>>>>> master
5450
You can pass an item as value to the dropdown and it will mark the specific item as selected for you.
5551
The value you can pass into the dropdown differs from the combination of tags you choose.
5652
When you specify the `multiple="1"` flag, the value can be a dropdown item or a list of dropdown items.
5753
In case you specify the `input-only="1"` flag the value must be a simple string!
58-
<<<<<<< HEAD
59-
Are those two flags not specified the value can be a dropdown item represented as an object or just it's value as a string.
60-
=======
6154
Are those two flags not specified the value can be a dropdown item represented as an object or just it's value as a string.
62-
>>>>>>> master
6355

6456
## Simple dropdown menu
6557
The simple dropdown menu only contains one level of menu items and provides the ability to select only one item at the same time.
6658
All changes are propagated via a custom change event which contains the selected item.
6759

6860
<ws-dropdown items.bind='["Item 1", "Item 2", "Item 3"]' text="Click me" change.delegate="log('dd1 changed', $event)"></ws-dropdown>
6961
```html
70-
<<<<<<< HEAD
71-
<ws-dropdown
72-
items='["Item 1", "Item 2", "Item 3"]'
73-
=======
7462
<ws-dropdown
75-
items='["Item 1", "Item 2", "Item 3"]'
76-
>>>>>>> master
63+
items='["Item 1", "Item 2", "Item 3"]'
7764
text="Click me">
7865
</ws-dropdown>
7966
```
8067

8168
## Hierarchical dropdown menu
8269
Sometimes not everything fits into one menu and we have to group our items and create a hierarchical menu.
83-
<<<<<<< HEAD
84-
This happens quite often on page headers or context menu's (right click). To create a hierarchical menu you
85-
=======
8670
This happens quite often on page headers or context menu's (right click). To create a hierarchical menu you
87-
>>>>>>> master
8871
just have to add the children for the dropdown item as you want.
8972

9073
<ws-dropdown items.bind='["Item 1", {"label": "Item 2", "children": ["Item 2.1", {"label": "Item 2.2", "children": ["Item 2.2.1", "Item 2.2.2", "Item 2.2.3", "Item 2.2.4"]}]}, "Item 3"]' text="Click me" change.delegate="log('dd1 changed', $event)"></ws-dropdown>
9174
```html
92-
<<<<<<< HEAD
93-
<ws-dropdown
94-
=======
9575
<ws-dropdown
96-
>>>>>>> master
9776
items='["Item 1", {"label": "Item 2", "children": ["Item 2.1", {"label": "Item 2.2", "children": ["Item 2.2.1", "Item 2.2.2", "Item 2.2.3", "Item 2.2.4"]}]}, "Item 3"]'
9877
text="Click me">
9978
</ws-dropdown>
@@ -121,17 +100,10 @@ interpreted as false.
121100
<ws-dropdown items.bind='["Item 1", "Item 2", "Item 3"]' value="Item 2" multiple="1" text="Select a value" type="select" style="display: inline-block; width: 150px"></ws-dropdown>
122101
```html
123102
<ws-dropdown
124-
<<<<<<< HEAD
125-
items='["Item 1", "Item 2", "Item 3"]'
126-
value="Item 2"
127-
text="Select a value"
128-
multiple="1"
129-
=======
130103
items='["Item 1", "Item 2", "Item 3"]'
131104
value="Item 2"
132105
text="Select a value"
133106
multiple="1"
134-
>>>>>>> master
135107
type="select">
136108
</ws-dropdown>
137109
```
@@ -146,21 +118,12 @@ the default filter with the attribute `filter="blue"` and the maximum amount of
146118
<ws-dropdown items.bind='["Car (Blue)", "Car (Red)", "Car (Orange)", "Bus (Blue)", "Bus (Red)", "Bus (Orange)", "Yet (Blue)", "Yet (Red)", "Yet (Orange)"]' filterable="1" filter="blue" limit="7" text="Select a value" type="select" style="display: inline-block; width: 150px"></ws-dropdown>
147119
```html
148120
<ws-dropdown
149-
<<<<<<< HEAD
150-
items.bind='["Car (Blue)", "Car (Red)", "Car (Orange)", "Bus (Blue)", "Bus (Red)", "Bus (Orange)", "Yet (Blue)", "Yet (Red)", "Yet (Orange)"]'
151-
filterable="1"
152-
filter="blue"
153-
limit="7"
154-
text="Select a value"
155-
type="select"
156-
=======
157121
items.bind='["Car (Blue)", "Car (Red)", "Car (Orange)", "Bus (Blue)", "Bus (Red)", "Bus (Orange)", "Yet (Blue)", "Yet (Red)", "Yet (Orange)"]'
158122
filterable="1"
159123
filter="blue"
160124
limit="7"
161125
text="Select a value"
162126
type="select"
163-
>>>>>>> master
164127
style="display: inline-block; width: 150px">
165128
</ws-dropdown>
166129
```
@@ -174,24 +137,27 @@ the `value` attribute also the `placeholder` attribute to set the placeholder fo
174137

175138
<ws-dropdown type="button" text="Click me" placeholder="Insert a text" value="Default value" input-only="1"></ws-dropdown>
176139
```html
177-
<<<<<<< HEAD
178-
<ws-dropdown
140+
<ws-dropdown
179141
type="button"
180142
text="Click me"
181-
placeholder="Insert a text"
182-
value="Default value"
143+
placeholder="Insert a text"
144+
value="Default value"
183145
input-only="1">
184146
</ws-dropdown>
185147
```
186148

187-
=======
188-
<ws-dropdown
189-
type="button"
149+
## Custom width
150+
Per default the dropdown has a width of 200px when the type is not select. For those select dropdown elements the default
151+
width is 100%. This means the dropdown is as wide as the select box. To change the width you can add the attribute
152+
`width` and give it a pixel, percent or any size value.
153+
154+
<ws-dropdown items.bind='["Item 1", "Item 2", "Item 3"]' text="Click me" type="button" width="500px"></ws-dropdown>
155+
```html
156+
<ws-dropdown
157+
items='["Item 1", "Item 2", "Item 3"]'
190158
text="Click me"
191-
placeholder="Insert a text"
192-
value="Default value"
193-
input-only="1">
159+
type="button"
160+
width="500px">
194161
</ws-dropdown>
195162
```
196163

197-
>>>>>>> master

src/ws-dropdown/ws-dropdown.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export class WSDropdown extends Component {
4040
limit: 10,
4141
orientation: 'left',
4242
placeholder: '',
43+
width: '',
4344
value: null,
4445
onChange: () => {},
4546
disabled: false
@@ -60,6 +61,7 @@ export class WSDropdown extends Component {
6061
limit: PropTypes.number,
6162
orientation: PropTypes.oneOf(['left', 'right']),
6263
placeholder: PropTypes.string,
64+
width: PropTypes.string,
6365
value: PropTypes.oneOfType([PropTypes.string, PropTypes.object, PropTypes.array]),
6466
onChange: PropTypes.func,
6567
disabled: PropTypes.bool
@@ -388,12 +390,13 @@ export class WSDropdown extends Component {
388390
* @returns {Object}
389391
*/
390392
render() {
391-
const isWide = this.props.type === 'select' ? 'mod-wide' : '';
393+
const isWide = this.props.type === 'select';
392394
return (
393395
<div className="dropdown" ref={element => { if (element) { this.element = element; } }}>
394396
{this.renderTrigger()}
395397
<div
396-
className={`dropdown-container ${this.props.orientation} ${isWide}`}
398+
className={`dropdown-container ${this.props.orientation}`}
399+
style={{width: this.props.width || (isWide ? '100%' : 'auto')}}
397400
ref={element => { if (element) { this.dropdownContainer = element; } }}
398401
>
399402
{this.renderContent()}

0 commit comments

Comments
 (0)