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): align Value.SummaryList when Value.* has no label #4311

Merged
merged 5 commits into from
Nov 21, 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 @@ -11,6 +11,7 @@ import {
OrderedListStylePositionExample,
OrderedListOtherTypesExample,
RemoveListExample,
DefinitionListHorizontalExampleWithoutDtValue,
} from 'Docs/uilib/elements/lists/Examples'

## Demos
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,13 @@ export function InheritLabel() {
</ComponentBox>
)
}

export const HorizontalLayoutWithoutLabel = () => (
<ComponentBox data-visual-test="forms-value-summary-horizontal-empty-label">
<Value.SummaryList layout="horizontal">
<Value.String value="foo" label="Foo" />
<Value.String value="bar" />
<Value.String value="baz" label="Baz" />
</Value.SummaryList>
</ComponentBox>
)
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,7 @@ Using [Value.Composition](/uilib/extensions/forms/Value/Composition/) to combine
### Inherit label

<Examples.InheritLabel />

<VisibleWhenVisualTest>
<Examples.HorizontalLayoutWithoutLabel />
</VisibleWhenVisualTest>
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,13 @@ describe('Field.SummaryList', () => {
})
expect(screenshot).toMatchImageSnapshot()
})

it('have to match without a label', async () => {
const screenshot = await makeScreenshot({
style: { width: '6rem' },
selector:
'[data-visual-test="forms-value-summary-horizontal-empty-label"] ',
})
expect(screenshot).toMatchImageSnapshot()
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ describe('Field.SummaryList', () => {
expect(element.getAttribute('aria-label')).toBe('Aria Label')
})

it('should have dnb-sr-only class when no label is given', () => {
render(
<SummaryList>
<Value.String value="Value" />
</SummaryList>
)
expect(document.querySelector('dt')).toHaveClass('dnb-sr-only')
})

it('should warn when child is not a Value.* component', () => {
const log = jest.spyOn(console, 'log').mockImplementation()

Expand Down
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 @@ -116,7 +116,12 @@ function ValueBlock(props: Props) {
value={{ ...summaryListContext, isNested: true }}
>
<Item>
<Dt className="dnb-forms-value-block__label">
<Dt
className={classnames(
'dnb-forms-value-block__label',
!label && 'dnb-sr-only'
)}
>
{label && <strong>{label}</strong>}
</Dt>
<Dd
Expand Down
Loading