1 | import { __rest } from "tslib";
|
2 | import * as React from 'react';
|
3 | import styles from '@patternfly/react-styles/css/components/FormControl/form-control';
|
4 | import { css } from '@patternfly/react-styles';
|
5 | import { ValidatedOptions } from '../../helpers/constants';
|
6 | import { getOUIAProps, getDefaultOUIAId } from '../../helpers';
|
7 | export class FormSelect extends React.Component {
|
8 | constructor(props) {
|
9 | super(props);
|
10 | this.handleChange = (event) => {
|
11 | this.props.onChange(event.currentTarget.value, event);
|
12 | };
|
13 | if (!props.id && !props['aria-label']) {
|
14 |
|
15 | console.error('FormSelect requires either an id or aria-label to be specified');
|
16 | }
|
17 | this.state = {
|
18 | ouiaStateId: getDefaultOUIAId(FormSelect.displayName, props.validated)
|
19 | };
|
20 | }
|
21 | render() {
|
22 | const _a = this.props, { children, className, value, validated, isDisabled, isRequired, isIconSprite, ouiaId, ouiaSafe } = _a, props = __rest(_a, ["children", "className", "value", "validated", "isDisabled", "isRequired", "isIconSprite", "ouiaId", "ouiaSafe"]);
|
23 |
|
24 | const selectedOption = React.Children.toArray(children).find((option) => option.props.value === value);
|
25 | const isSelectedPlaceholder = selectedOption && selectedOption.props.isPlaceholder;
|
26 | return (React.createElement("select", Object.assign({}, props, { className: css(styles.formControl, isIconSprite && styles.modifiers.iconSprite, className, validated === ValidatedOptions.success && styles.modifiers.success, validated === ValidatedOptions.warning && styles.modifiers.warning, isSelectedPlaceholder && styles.modifiers.placeholder), "aria-invalid": validated === ValidatedOptions.error }, getOUIAProps(FormSelect.displayName, ouiaId !== undefined ? ouiaId : this.state.ouiaStateId, ouiaSafe), { onChange: this.handleChange, disabled: isDisabled, required: isRequired, value: value }), children));
|
27 | }
|
28 | }
|
29 | FormSelect.displayName = 'FormSelect';
|
30 | FormSelect.defaultProps = {
|
31 | className: '',
|
32 | value: '',
|
33 | validated: 'default',
|
34 | isDisabled: false,
|
35 | isRequired: false,
|
36 | isIconSprite: false,
|
37 | onBlur: () => undefined,
|
38 | onFocus: () => undefined,
|
39 | onChange: () => undefined,
|
40 | ouiaSafe: true
|
41 | };
|
42 |
|
\ | No newline at end of file |