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

fix(Forms): render given elements to warning and info properties #4261

Merged
merged 1 commit into from
Nov 12, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ function FieldBlock(props: Props) {
if (messages.length > 0) {
acc[type] = {
...acc[type],
text: <CombineMessages type={type} messages={messages} />,
children: <CombineMessages type={type} messages={messages} />,
}

fieldStateIdsRef.current[type] = id
Expand Down Expand Up @@ -682,7 +682,7 @@ export function getMessagesFromError(
return [
((content instanceof Error && content.message) ||
(content instanceof FormError && content.message) ||
content?.toString() ||
(React.isValidElement(content) ? content : content?.toString()) ||
content) as StateMessage,
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,33 @@ describe('FieldBlock', () => {
expect(element).toHaveClass('dnb-height-animation--is-visible')
expect(element).toHaveTextContent(blockInfo)
})

it('should render the given element', () => {
render(
<FieldBlock info={<strong>{blockInfo}</strong>}>
content
</FieldBlock>
)

const element = document.querySelector('.dnb-form-status')

expect(element).toBeInTheDocument()
expect(element).toHaveClass('dnb-form-status--info')
expect(element).toHaveClass('dnb-height-animation--is-visible')
expect(element).toHaveTextContent(blockInfo)
})

it('should render the given React component', () => {
const MockComponent = () => <strong>{blockInfo}</strong>
render(<FieldBlock info={<MockComponent />}>content</FieldBlock>)

const element = document.querySelector('.dnb-form-status')

expect(element).toBeInTheDocument()
expect(element).toHaveClass('dnb-form-status--info')
expect(element).toHaveClass('dnb-height-animation--is-visible')
expect(element).toHaveTextContent(blockInfo)
})
})

describe('warning prop', () => {
Expand All @@ -713,6 +740,21 @@ describe('FieldBlock', () => {
expect(element).toHaveClass('dnb-height-animation--is-visible')
expect(element).toHaveTextContent(blockWarning)
})

it('should render the given element', () => {
render(
<FieldBlock warning={<strong>{blockWarning}</strong>}>
content
</FieldBlock>
)

const element = document.querySelector('.dnb-form-status')

expect(element).toBeInTheDocument()
expect(element).toHaveClass('dnb-form-status--warn')
expect(element).toHaveClass('dnb-height-animation--is-visible')
expect(element).toHaveTextContent(blockWarning)
})
})

describe('error prop', () => {
Expand Down
Loading