Skip to content
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

Make InputGroup label reflect required prop (#510) #511

Merged
merged 2 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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
Loading