Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion src/components/InputGroup/InputGroup.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const InputGroup = ({
return null;
}

const validationState = children.reduce(
const validationState = React.Children.toArray(children).reduce(
(state, child) => {
if (state === 'invalid' || (state === 'warning' && child.props.validationState === 'valid')) {
return state;
Expand Down
2 changes: 2 additions & 0 deletions src/components/InputGroup/__tests__/InputGroup.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
InputGroupWithCustomInputPropsForTest,
InputGroupWithoutChildrenForTest,
} from './InputGroup.story';
import { childrenPropTest } from './_propTests/childrenPropTest';
import { validationTextsPropTest } from './_propTests/validationTextsPropTest';
import { validationStatePropTest } from './_propTests/validationStatePropTest';

Expand All @@ -17,6 +18,7 @@ test.describe('InputGroup', () => {
test.describe('visual', () => {
[
...propTests.defaultComponentPropTest,
...childrenPropTest,
...propTests.disabledPropTest,
...propTests.isLabelVisiblePropTest,
...propTests.layoutPropTest,
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 20 additions & 10 deletions src/components/InputGroup/__tests__/InputGroup.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,30 @@ const options = [
},
];

const defaultChildren = [
<SelectField
key="selectField"
label="Select label"
options={options}
value={options[0].value}
/>,
<TextField
key="textField"
label="Text label"
placeholder="Placeholder"
/>,
<Button
key="button"
label="Submit"
/>,
];

export const InputGroupForTest = ({
children,
...props
}: InputGroupTestProps) => (
<InputGroup label="Input group label" {...props}>
<SelectField
label="Select label"
options={options}
value={options[0].value}
/>
<TextField
label="Text label"
placeholder="Placeholder"
/>
<Button label="Submit" />
{children ?? defaultChildren}
</InputGroup>
);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import React from 'react';
import type { PropTests } from '../../../../../tests/playwright/types';
import { ButtonWithGlobalProps as Button } from '../../../Button/Button';
import { SelectFieldWithGlobalProps as SelectField } from '../../../SelectField/SelectField';
import { TextFieldWithGlobalProps as TextField } from '../../../TextField/TextField';

const options = [
{
label: 'Option 1',
value: 'option1',
},
{
label: 'Option 2',
value: 'option2',
},
{
label: 'Option 3',
value: 'option3',
},
];

export const childrenPropTest: PropTests = [
{
name: 'children:node[single]',
props: {
children: (
<TextField
label="Text label"
placeholder="Placeholder"
/>
),
},
},
{
name: 'children:node[multiple]',
props: {
children: [
<SelectField
key="selectField"
label="Select label"
options={options}
value={options[0].value}
/>,
<TextField
key="textField"
label="Text label"
placeholder="Placeholder"
/>,
<Button
key="button"
label="Submit"
/>,
],
},
},
];
Loading