Skip to content

Commit

Permalink
Make InputGroup label reflect required prop (#510)
Browse files Browse the repository at this point in the history
  • Loading branch information
hubacekj authored and adamkudrna committed Dec 4, 2023
1 parent ba6ac9d commit 02e7d66
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/components/InputGroup/InputGroup.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const InputGroup = ({
isLabelVisible,
label,
layout,
required,
size,
validationTexts,
...restProps
Expand Down Expand Up @@ -57,6 +58,7 @@ export const InputGroup = ({
? styles.isRootLayoutHorizontal
: styles.isRootLayoutVertical,
disabled && styles.isRootDisabled,
required && styles.isRootRequired,
getRootSizeClassName(size, styles),
getRootValidationStateClassName(validationState, styles),
)}
Expand Down Expand Up @@ -112,6 +114,7 @@ InputGroup.defaultProps = {
id: undefined,
isLabelVisible: true,
layout: 'vertical',
required: false,
size: 'medium',
validationTexts: null,
};
Expand Down Expand Up @@ -156,6 +159,11 @@ InputGroup.propTypes = {
* as the value is inherited in such case.
*/
layout: PropTypes.oneOf(['horizontal', 'vertical']),
/**
* If `true`, the `InputGroup`'s label appears as required. Underlying `<fieldset>`
* element does not take `required` attribute so there is no functional effect.
*/
required: PropTypes.bool,
/**
* Size of the `children` elements.
*/
Expand Down
4 changes: 4 additions & 0 deletions src/components/InputGroup/InputGroup.scss
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
@include foundation.help-text();
}

.isRootRequired .label {
@include foundation.label-required();
}

// States
.isRootStateInvalid {
@include variants.validation(invalid);
Expand Down
6 changes: 6 additions & 0 deletions src/components/InputGroup/__tests__/InputGroup.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ describe('rendering', () => {
expect(within(rootElement).getByText('validation text 2'));
},
],
[
{ required: true },
(rootElement) => {
expect(rootElement).toHaveClass('isRootRequired');
},
],
])('renders with props: "%s"', (testedProps, assert) => {
const dom = render((
<InputGroup
Expand Down

0 comments on commit 02e7d66

Please sign in to comment.