Skip to content

Commit 93fbe48

Browse files
committed
Make InputGroup label reflect required prop (#510)
1 parent ba6ac9d commit 93fbe48

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

src/components/InputGroup/InputGroup.jsx

+8
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export const InputGroup = ({
2222
isLabelVisible,
2323
label,
2424
layout,
25+
required,
2526
size,
2627
validationTexts,
2728
...restProps
@@ -57,6 +58,7 @@ export const InputGroup = ({
5758
? styles.isRootLayoutHorizontal
5859
: styles.isRootLayoutVertical,
5960
disabled && styles.isRootDisabled,
61+
required && styles.isRootRequired,
6062
getRootSizeClassName(size, styles),
6163
getRootValidationStateClassName(validationState, styles),
6264
)}
@@ -112,6 +114,7 @@ InputGroup.defaultProps = {
112114
id: undefined,
113115
isLabelVisible: true,
114116
layout: 'vertical',
117+
required: false,
115118
size: 'medium',
116119
validationTexts: null,
117120
};
@@ -156,6 +159,11 @@ InputGroup.propTypes = {
156159
* as the value is inherited in such case.
157160
*/
158161
layout: PropTypes.oneOf(['horizontal', 'vertical']),
162+
/**
163+
* If `true`, the `InputGroup`'s label appears as required. Underlying `<fieldset>`
164+
* element does not take `required` attribute so there is no functional effect.
165+
*/
166+
required: PropTypes.bool,
159167
/**
160168
* Size of the `children` elements.
161169
*/

src/components/InputGroup/InputGroup.scss

+4
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@
4141
@include foundation.help-text();
4242
}
4343

44+
.isRootRequired .label {
45+
@include foundation.label-required();
46+
}
47+
4448
// States
4549
.isRootStateInvalid {
4650
@include variants.validation(invalid);

src/components/InputGroup/__tests__/InputGroup.test.jsx

+6
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@ describe('rendering', () => {
9999
expect(within(rootElement).getByText('validation text 2'));
100100
},
101101
],
102+
[
103+
{ required: true },
104+
(rootElement) => {
105+
expect(rootElement).toHaveClass('isRootRequired');
106+
},
107+
],
102108
])('renders with props: "%s"', (testedProps, assert) => {
103109
const dom = render((
104110
<InputGroup

0 commit comments

Comments
 (0)