Skip to content

Commit

Permalink
Display help always under the label
Browse files Browse the repository at this point in the history
  • Loading branch information
tujoworker committed Nov 15, 2024
1 parent db86d3d commit a82f46d
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1736,15 +1736,14 @@ describe('DataContext.Provider', () => {

const input = document.querySelector('input')
const indicator = document.querySelector(
'label .dnb-forms-submit-indicator'
'.dnb-forms-submit-indicator'
)

// Use fireEvent over userEvent, because of its sync nature
fireEvent.change(input, {
target: { value: '123' },
})

expect(indicator).toHaveTextContent('My label...')
expect(indicator).toHaveClass(
'dnb-forms-submit-indicator--state-pending'
)
Expand All @@ -1770,15 +1769,14 @@ describe('DataContext.Provider', () => {

const input = document.querySelector('input')
const indicator = document.querySelector(
'label .dnb-forms-submit-indicator'
'.dnb-forms-submit-indicator'
)

// Use fireEvent over userEvent, because of its sync nature
fireEvent.change(input, {
target: { value: '123' },
})

expect(indicator).toHaveTextContent('My label...')
expect(indicator).toHaveClass(
'dnb-forms-submit-indicator--state-pending'
)
Expand Down Expand Up @@ -2084,22 +2082,20 @@ describe('DataContext.Provider', () => {

const input = document.querySelector('input')
const indicator = document.querySelector(
'label .dnb-forms-submit-indicator'
'.dnb-forms-submit-indicator'
)

await userEvent.type(input, '123')

await waitFor(() => {
expect(events).toEqual(['validator'])
expect(indicator).toHaveTextContent('My label...')
expect(indicator).toHaveClass(
'dnb-forms-submit-indicator--state-pending'
)
})

await waitFor(() => {
expect(events).toEqual(['validator', 'onChangeForm'])
expect(indicator).toHaveTextContent('My label...')
expect(indicator).toHaveClass(
'dnb-forms-submit-indicator--state-pending'
)
Expand All @@ -2111,7 +2107,6 @@ describe('DataContext.Provider', () => {
'onChangeForm',
'onChangeField',
])
expect(indicator).toHaveTextContent('My label...')
expect(indicator).toHaveClass(
'dnb-forms-submit-indicator--state-complete'
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -531,14 +531,6 @@ function FieldBlock(props: Props) {
: labelDescription
const hasHelp = help?.title || help?.content

const helpNode = (
<HelpButtonInlineContent
contentId={`${id}-help`}
className="dnb-forms-field-block__help"
help={help}
/>
)

return (
<FieldBlockContext.Provider
value={{
Expand All @@ -557,8 +549,6 @@ function FieldBlock(props: Props) {
className={mainClasses}
{...rest}
>
{hasHelp && layout === 'horizontal' && helpNode}

<div className={gridClasses}>
{(label || labelDescription || hasHelp) && (
<FormLabel {...labelProps}>
Expand All @@ -582,7 +572,13 @@ function FieldBlock(props: Props) {
</FormLabel>
)}

{hasHelp && helpNode}
{hasHelp && (
<HelpButtonInlineContent
contentId={`${id}-help`}
className="dnb-forms-field-block__help"
help={help}
/>
)}

<div
className={classnames(
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.
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.
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.
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ fieldset.dnb-forms-field-block {
auto;
grid-template-areas:
'label contents'
'help help'
'. indicator'
'. status';

Expand All @@ -126,17 +127,6 @@ fieldset.dnb-forms-field-block {
}
}

&__help:has(+ #{&}__grid#{&}--layout-horizontal) {
@include allBelow(small) {
display: none;
}
}
&__grid#{&}--layout-horizontal &__help {
@include allAbove(small) {
display: none;
}
}

&__indicator {
grid-area: indicator;
}
Expand All @@ -154,6 +144,14 @@ fieldset.dnb-forms-field-block {
}
}
}
&__grid#{&}--layout-horizontal &__help {
@include allAbove(small) {
.dnb-section {
margin-top: 0.5rem;
margin-bottom: 0;
}
}
}

&__status {
grid-area: status;
Expand Down

0 comments on commit a82f46d

Please sign in to comment.