Skip to content

Commit fe37bc3

Browse files
committed
Add correct classname for a required select menu.
1 parent 8b57805 commit fe37bc3

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/components/select.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as React from 'react';
2+
import classNames from 'classnames/dedupe';
23
import {componentDefaultProps} from './component-common';
34
import ErrorMessages from './error-messages';
45
import Help from './help';
@@ -47,21 +48,26 @@ class Select extends React.Component<SelectProps, {}> {
4748

4849
public render(): JSX.Element {
4950
const {
51+
className,
5052
errorMessages,
5153
help,
5254
id,
5355
layout,
5456
name,
57+
required,
5558
showErrors,
5659
...inputProps
5760
} = this.props;
5861
Object.keys(componentDefaultProps).forEach((key): void => {
5962
delete inputProps[key];
6063
});
6164

65+
const markAsInvalid = showErrors && (errorMessages.length > 0 || required);
66+
6267
const control = (
6368
<SelectControl
6469
{...inputProps}
70+
className={classNames(markAsInvalid ? ['is-invalid', className] : className)}
6571
elementRef={this.props.elementRef}
6672
id={id}
6773
name={name}

0 commit comments

Comments
 (0)