Skip to content

Select component props passthrough #670

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## react-components 5.34.10 (2024-06-24)

- [Select] Pass through additional props to select inner component (by [@sean-mckenna](https://github.com/sean-mckenna))
- [Button] Remove button loading background colour (by [@sean-mckenna](https://github.com/sean-mckenna))

## react-components 5.34.9 (2024-04-29)

- [Logo] Adjust Security Compliance Management logo viewBox to match Continuous Delivery (by [@Lukeaber](https://github.com/Lukeaber))
Expand Down
4 changes: 2 additions & 2 deletions packages/react-components/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@puppet/react-components",
"version": "5.34.9",
"version": "5.34.10",
"author": "Puppet, Inc.",
"license": "Apache-2.0",
"main": "build/library.js",
Expand Down Expand Up @@ -91,4 +91,4 @@
"regenerator-runtime": "^0.13.7",
"scroll-into-view-if-needed": "^2.2.25"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,11 @@ class Select extends Component {
style,
type,
value,
actionLabel,
onChange,
onFilter,
onBlur: onBlurProp,
...restProps
} = this.props;

let input;
Expand Down Expand Up @@ -411,6 +416,7 @@ class Select extends Component {
}}
onChange={onValueChange}
autoComplete="off"
{...restProps}
/>
);
break;
Expand All @@ -431,6 +437,7 @@ class Select extends Component {
ref={button => {
this.button = button;
}}
{...restProps}
/>
<input
type="hidden"
Expand Down
90 changes: 58 additions & 32 deletions packages/react-components/source/react/library/select/Select.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const options = [
options={options}
value={value}
onChange={newValue => setValue(newValue)}
/>
/>;
```

### Nonexistent value
Expand Down Expand Up @@ -61,17 +61,23 @@ const isValueInOptions = options.map(option => option.value).includes(value);
value={value}
onChange={newValue => setValue(newValue)}
/>
{!isValueInOptions && <Alert type="warning" style={{ marginTop: 10 }}>"{value}" is not an option</Alert>}
</>
{!isValueInOptions && (
<Alert type="warning" style={{ marginTop: 10 }}>
"{value}" is not an option
</Alert>
)}
</>;
```

## Variations

### Autocomplete

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.
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.

```jsx
const [fieldValue, setFieldValue] = React.useState('');

const options = [
{ value: 'apple', label: 'apple' },
{ value: 'orange', label: 'orange' },
Expand All @@ -86,16 +92,30 @@ const options = [

const style = { margin: 10 };

const noResults = [
{
value: [],
label: 'No results found',
},
];

let filteredOptions = [...options];
if (state.fieldValue !== undefined && state.fieldValue !== '') {
filteredOptions = options.filter(options =>
options.label.includes(state.fieldValue),
);
}

<div>
<Select
name="autocomplete-example"
options={options}
options={filteredOptions.length === 0 ? noResults : filteredOptions}
placeholder="Select your fruit"
style={style}
value={state.value1}
onChange={value1 => {
console.log('New Value:', value1);
setState({ value1 });
value={state.fieldValue}
onChange={fieldValue => {
console.log('New Value:', fieldValue);
setState({ fieldValue });
}}
onBlur={() => {
console.log('onBlur');
Expand All @@ -111,35 +131,40 @@ To render an option group, provide an array of child options as the value for a
still have labels, and if a parent is disabled, all its child options will be disabled, too.

```jsx
const optionsWithGroups = [{
label: "Spices",
value: [
{label: "Cinnamon", value: "cinnamon"},
{label: "Coriander", value: "coriander"},
{label: "Cumin", value: "cumin"},
]
}, {
label: "Oil",
value: "oil"
}, {
label: "Vinegar",
value: "vinegar"
}, {
label: "Herbs",
disabled: true,
value: [
{label: "Parsley", value: "parsley"},
{label: "Sage", value: "sage"},
{label: "Rosemary", value: "rosemary"},
]
}];
const optionsWithGroups = [
{
label: 'Spices',
value: [
{ label: 'Cinnamon', value: 'cinnamon' },
{ label: 'Coriander', value: 'coriander' },
{ label: 'Cumin', value: 'cumin' },
],
},
{
label: 'Oil',
value: 'oil',
},
{
label: 'Vinegar',
value: 'vinegar',
},
{
label: 'Herbs',
disabled: true,
value: [
{ label: 'Parsley', value: 'parsley' },
{ label: 'Sage', value: 'sage' },
{ label: 'Rosemary', value: 'rosemary' },
],
},
];

<Select
name="select-option-group-example"
options={optionsWithGroups}
value={state.value}
onChange={value => {
setState({value});
setState({ value });
}}
/>;
```
Expand Down Expand Up @@ -228,6 +253,7 @@ const style = { margin: 10 };
```

## Option properties

### Disabled options

Use the `disabled` object property to disable a row in a dropdown.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,7 @@ $puppet-button-padding-vertical: 5px;
@include button-type-properties(map-get($typedef, hover));
}

&:active,
&.rc-button-loading {
&:active {
@include button-type-properties(map-get($typedef, active));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
padding-left: 31px;
}

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

Expand All @@ -125,7 +125,7 @@
right: $puppet-common-spacing-base * 4 - 1;
}

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