Skip to content

Commit 31bd2f7

Browse files
author
Rhyza Velasco
authored
Merge pull request #199 from puppetlabs/pds-416-buttonselect-width-prop
Fix and add custom width to ActionSelect and ButtonSelect
2 parents 054b0ff + 867540b commit 31bd2f7

File tree

5 files changed

+78
-1
lines changed

5 files changed

+78
-1
lines changed

packages/react-components/source/react/library/action-select/ActionSelect.js

+5
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ const propTypes = {
5353
loading: PropTypes.bool,
5454
/** Optional additional className passed to the outer element */
5555
className: PropTypes.string,
56+
/** Optional inline width passed to the button element */
57+
width: PropTypes.string,
5658
/** Optional inline style passed to the outer element */
5759
style: PropTypes.shape({}),
5860
};
@@ -68,6 +70,7 @@ const defaultProps = {
6870
loading: false,
6971
disabled: false,
7072
className: '',
73+
width: null,
7174
style: {},
7275
};
7376

@@ -147,6 +150,7 @@ class ActionSelect extends Component {
147150
actions,
148151
weight,
149152
className,
153+
width,
150154
style,
151155
} = this.props;
152156

@@ -172,6 +176,7 @@ class ActionSelect extends Component {
172176
weight={weight}
173177
icon={icon}
174178
trailingIcon={icon ? null : 'chevron-down'}
179+
style={width ? { width, textAlign: 'left' } : null}
175180
disabled={disabled}
176181
loading={loading}
177182
aria-haspopup="true"

packages/react-components/source/react/library/action-select/ActionSelect.md

+44
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,50 @@ const style = { display: 'inline-block', margin: 10 };
173173
</div>;
174174
```
175175

176+
### Custom Width
177+
178+
Use the `width` prop to customize the width of the button.
179+
180+
```jsx
181+
const actions = [
182+
{
183+
id: 'one',
184+
icon: 'pencil',
185+
label: 'Do thing one',
186+
onClick() {
187+
console.log('Thing one');
188+
},
189+
},
190+
{
191+
id: 'two',
192+
icon: 'send',
193+
label: 'Do thing two',
194+
onClick() {
195+
console.log('Thing two');
196+
},
197+
},
198+
{
199+
id: 'three',
200+
as: 'a',
201+
href: 'https://www.google.com',
202+
target: '_blank',
203+
label: 'Open link',
204+
icon: 'link',
205+
},
206+
];
207+
208+
const style = { display: 'inline-block', margin: 10 };
209+
210+
<div>
211+
<ActionSelect
212+
actions={actions}
213+
label="Choose an Action"
214+
style={style}
215+
width="200px"
216+
/>
217+
</div>;
218+
```
219+
176220
## Related
177221

178222
- [ButtonSelect](#/React%20Components/ButtonSelect)

packages/react-components/source/react/library/button-select/ButtonSelect.js

+5
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ const propTypes = {
6666
loading: PropTypes.bool,
6767
/** Optional additional className passed to the outer element */
6868
className: PropTypes.string,
69+
/** Optional inline width passed to the button element */
70+
width: PropTypes.string,
6971
/** Optional inline style passed to the outer element */
7072
style: PropTypes.shape({}),
7173
};
@@ -86,6 +88,7 @@ const defaultProps = {
8688
loading: false,
8789
disabled: false,
8890
className: '',
91+
width: null,
8992
style: {},
9093
};
9194

@@ -234,6 +237,7 @@ class ButtonSelect extends Component {
234237
options,
235238
weight,
236239
className,
240+
width,
237241
style,
238242
value,
239243
} = this.props;
@@ -263,6 +267,7 @@ class ButtonSelect extends Component {
263267
weight={weight}
264268
icon={icon}
265269
trailingIcon={icon ? null : 'chevron-down'}
270+
style={width ? { width, textAlign: 'left' } : null}
266271
disabled={disabled}
267272
loading={loading}
268273
aria-haspopup="true"

packages/react-components/source/react/library/button-select/ButtonSelect.md

+23
Original file line numberDiff line numberDiff line change
@@ -219,3 +219,26 @@ const style = { display: 'inline-block', margin: 10 };
219219
/>
220220
</div>;
221221
```
222+
223+
### Custom Width
224+
225+
Use the `width` prop to customize the width of the button.
226+
227+
```jsx
228+
const options = [
229+
{ value: 'hello', label: 'Hello' },
230+
{ value: 'world', label: 'World' },
231+
{ value: 'hi', label: 'Hi' },
232+
{ value: 'mom', label: 'Mom' },
233+
];
234+
235+
<ButtonSelect
236+
options={options}
237+
value={state.value}
238+
onChange={value => {
239+
console.log('New Value:', value);
240+
setState({ value });
241+
}}
242+
width="100px"
243+
/>
244+
```

packages/react-components/source/scss/library/components/_button.scss

+1-1
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ $puppet-button-padding-vertical: 5px;
338338
}
339339
}
340340

341-
.rc-button-trailing-icon:not(.rc-button-text).rc-button-trailing-icon:focus {
341+
.rc-button-inner-focus.rc-button-trailing-icon:not(.rc-button-text).rc-button-trailing-icon:focus {
342342
&.rc-button-full {
343343
padding-right: 32px;
344344
}

0 commit comments

Comments
 (0)