Skip to content

Commit de66109

Browse files
committed
Select component props passthrough (#670)
- Allow additional props such as data-testid to be passed to the inner select component. - Add more useful select autocomplete styleguide example. - Set the input icon button loading style to transparent.
1 parent 40661c1 commit de66109

File tree

5 files changed

+73
-36
lines changed

5 files changed

+73
-36
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@
5757

5858
- Upgrade dependencies #450
5959

60+
## react-components 5.34.10 (2024-06-24)
61+
62+
- [Select] Pass through additional props to select inner component (by [@sean-mckenna](https://github.com/sean-mckenna))
63+
- [Button] Remove button loading background colour (by [@sean-mckenna](https://github.com/sean-mckenna))
64+
6065
## react-components 5.34.9 (2024-04-29)
6166

6267
- [Logo] Adjust Security Compliance Management logo viewBox to match Continuous Delivery (by [@Lukeaber](https://github.com/Lukeaber))

packages/react-components/source/react/library/select/Select.js

+7
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,11 @@ class Select extends Component {
380380
style,
381381
type,
382382
value,
383+
actionLabel,
384+
onChange,
385+
onFilter,
386+
onBlur: onBlurProp,
387+
...restProps
383388
} = this.props;
384389

385390
let input;
@@ -411,6 +416,7 @@ class Select extends Component {
411416
}}
412417
onChange={onValueChange}
413418
autoComplete="off"
419+
{...restProps}
414420
/>
415421
);
416422
break;
@@ -431,6 +437,7 @@ class Select extends Component {
431437
ref={button => {
432438
this.button = button;
433439
}}
440+
{...restProps}
434441
/>
435442
<input
436443
type="hidden"

packages/react-components/source/react/library/select/Select.md

+58-32
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const options = [
3030
options={options}
3131
value={value}
3232
onChange={newValue => setValue(newValue)}
33-
/>
33+
/>;
3434
```
3535

3636
### Nonexistent value
@@ -61,17 +61,23 @@ const isValueInOptions = options.map(option => option.value).includes(value);
6161
value={value}
6262
onChange={newValue => setValue(newValue)}
6363
/>
64-
{!isValueInOptions && <Alert type="warning" style={{ marginTop: 10 }}>"{value}" is not an option</Alert>}
65-
</>
64+
{!isValueInOptions && (
65+
<Alert type="warning" style={{ marginTop: 10 }}>
66+
"{value}" is not an option
67+
</Alert>
68+
)}
69+
</>;
6670
```
6771

6872
## Variations
6973

7074
### Autocomplete
7175

72-
With `type` set to `autocomplete`, the `Select` input will accept text and provide filtered menu options accordingly. Full keyboard navigation of the menu options is retained.
76+
With `type` set to `autocomplete`, the `Select` input will accept text and the menu options can be filtered accordingly. Full keyboard navigation of the menu options is retained.
7377

7478
```jsx
79+
const [fieldValue, setFieldValue] = React.useState('');
80+
7581
const options = [
7682
{ value: 'apple', label: 'apple' },
7783
{ value: 'orange', label: 'orange' },
@@ -86,16 +92,30 @@ const options = [
8692

8793
const style = { margin: 10 };
8894

95+
const noResults = [
96+
{
97+
value: [],
98+
label: 'No results found',
99+
},
100+
];
101+
102+
let filteredOptions = [...options];
103+
if (state.fieldValue !== undefined && state.fieldValue !== '') {
104+
filteredOptions = options.filter(options =>
105+
options.label.includes(state.fieldValue),
106+
);
107+
}
108+
89109
<div>
90110
<Select
91111
name="autocomplete-example"
92-
options={options}
112+
options={filteredOptions.length === 0 ? noResults : filteredOptions}
93113
placeholder="Select your fruit"
94114
style={style}
95-
value={state.value1}
96-
onChange={value1 => {
97-
console.log('New Value:', value1);
98-
setState({ value1 });
115+
value={state.fieldValue}
116+
onChange={fieldValue => {
117+
console.log('New Value:', fieldValue);
118+
setState({ fieldValue });
99119
}}
100120
onBlur={() => {
101121
console.log('onBlur');
@@ -111,35 +131,40 @@ To render an option group, provide an array of child options as the value for a
111131
still have labels, and if a parent is disabled, all its child options will be disabled, too.
112132

113133
```jsx
114-
const optionsWithGroups = [{
115-
label: "Spices",
116-
value: [
117-
{label: "Cinnamon", value: "cinnamon"},
118-
{label: "Coriander", value: "coriander"},
119-
{label: "Cumin", value: "cumin"},
120-
]
121-
}, {
122-
label: "Oil",
123-
value: "oil"
124-
}, {
125-
label: "Vinegar",
126-
value: "vinegar"
127-
}, {
128-
label: "Herbs",
129-
disabled: true,
130-
value: [
131-
{label: "Parsley", value: "parsley"},
132-
{label: "Sage", value: "sage"},
133-
{label: "Rosemary", value: "rosemary"},
134-
]
135-
}];
134+
const optionsWithGroups = [
135+
{
136+
label: 'Spices',
137+
value: [
138+
{ label: 'Cinnamon', value: 'cinnamon' },
139+
{ label: 'Coriander', value: 'coriander' },
140+
{ label: 'Cumin', value: 'cumin' },
141+
],
142+
},
143+
{
144+
label: 'Oil',
145+
value: 'oil',
146+
},
147+
{
148+
label: 'Vinegar',
149+
value: 'vinegar',
150+
},
151+
{
152+
label: 'Herbs',
153+
disabled: true,
154+
value: [
155+
{ label: 'Parsley', value: 'parsley' },
156+
{ label: 'Sage', value: 'sage' },
157+
{ label: 'Rosemary', value: 'rosemary' },
158+
],
159+
},
160+
];
136161

137162
<Select
138163
name="select-option-group-example"
139164
options={optionsWithGroups}
140165
value={state.value}
141166
onChange={value => {
142-
setState({value});
167+
setState({ value });
143168
}}
144169
/>;
145170
```
@@ -228,6 +253,7 @@ const style = { margin: 10 };
228253
```
229254

230255
## Option properties
256+
231257
### Disabled options
232258

233259
Use the `disabled` object property to disable a row in a dropdown.

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,7 @@ $puppet-button-padding-vertical: 5px;
152152
@include button-type-properties(map-get($typedef, hover));
153153
}
154154

155-
&:active,
156-
&.rc-button-loading {
155+
&:active {
157156
@include button-type-properties(map-get($typedef, active));
158157
}
159158

packages/react-components/source/scss/library/components/forms/_input.scss

+2-2
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
padding-left: 31px;
9999
}
100100

101-
.rc-input-icon.trailing ~ .rc-input {
101+
.rc-input:has(+ .rc-input-icon.trailing) {
102102
padding-right: 31px;
103103
}
104104

@@ -125,7 +125,7 @@
125125
right: $puppet-common-spacing-base * 4 - 1;
126126
}
127127

128-
.rc-input-icon.trailing ~ .rc-input {
128+
.rc-input:has(+ .rc-input-icon.trailing) {
129129
padding-right: $puppet-common-spacing-base * 10 - 1;
130130
}
131131
}

0 commit comments

Comments
 (0)