Skip to content

Commit

Permalink
fix(FormStatus): ensure content given as children will be displayed…
Browse files Browse the repository at this point in the history
… in linked GlobalStatus (#4547)
  • Loading branch information
tujoworker authored Feb 6, 2025
1 parent 8b0ce9f commit bc8f89d
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/dnb-eufemia/src/components/form-status/FormStatus.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,14 +188,14 @@ export default class FormStatus extends React.PureComponent {
(provider) => {
// gets called once ready
if (this.props.state === 'error' && this.isReadyToGetVisible()) {
const { state, text, globalStatus, label } =
const { state, text, children, globalStatus, label } =
this.getProps(context)
provider.add({
state,
status_id: this.getStatusId(),
item: {
item_id: this.state.id,
text: globalStatus?.message || text,
text: globalStatus?.message || text || children,
status_anchor_label: label,
status_anchor_url: true,
},
Expand Down Expand Up @@ -280,7 +280,7 @@ export default class FormStatus extends React.PureComponent {
status_id,
item: {
item_id: this.state.id,
text: globalStatus?.message || text,
text: globalStatus?.message || text || children,
status_anchor_label: label,
status_anchor_url: true,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,10 @@ describe('FormStatus component', () => {
).toHaveTextContent('Custom GlobalStatus Title')
})

expect(
document.querySelector('.dnb-global-status__message__content')
).toHaveTextContent('has error')

// Close the GlobalStatus
rerender(
<>
Expand All @@ -259,6 +263,37 @@ describe('FormStatus component', () => {
document.querySelector('.dnb-global-status__title')
).toBeNull()
})

// Show the GlobalStatus and set a custom title
rerender(
<>
<GlobalStatus id="my-status" />
<Provider
FormStatus={{
className: 'bar',
globalStatus: {
id: 'my-status',
show: true,
title: 'Custom GlobalStatus Title',
},
}}
>
<FormStatus>has error given as children</FormStatus>
</Provider>
</>
)

expect(document.querySelector('.dnb-form-status')).toHaveClass('bar')

await waitFor(() => {
expect(
document.querySelector('.dnb-global-status__title')
).toHaveTextContent('Custom GlobalStatus Title')
})

expect(
document.querySelector('.dnb-global-status__message__content')
).toHaveTextContent('has error given as children')
})

it('should support spacing props', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2536,6 +2536,10 @@ describe('DataContext.Provider', () => {
).toHaveTextContent(nb.Field.errorSummaryTitle)
})

expect(
document.querySelector('.dnb-global-status__message__content')
).toHaveTextContent(nb.Field.errorRequired + 'Gå til')

await userEvent.type(input, 'foo')
fireEvent.blur(input)

Expand Down

0 comments on commit bc8f89d

Please sign in to comment.