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: fix vertical label_direction support for Radio group and ToggleButton group #2899

Merged
merged 2 commits into from
Nov 14, 2023
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
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.
11 changes: 7 additions & 4 deletions packages/dnb-eufemia/src/components/radio/RadioGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,14 +239,17 @@ export default class RadioGroup extends React.PureComponent {
<fieldset>
<Flex.Container
align="baseline"
direction={vertical ? 'vertical' : 'horizontal'}
direction={
vertical || label_direction === 'vertical'
? 'vertical'
: 'horizontal'
}
spacing={vertical ? 'x-small' : undefined}
>
<FormLabel
element="legend"
label_id={id + '-label'}
label_direction={label_direction}
label_sr_only={label_sr_only}
id={id + '-label'}
srOnly={label_sr_only}
>
{label}
</FormLabel>
Expand Down
44 changes: 42 additions & 2 deletions packages/dnb-eufemia/src/components/radio/__tests__/Radio.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ describe('Radio group component', () => {
).toEqual([
'dnb-space',
'dnb-flex-container',
'dnb-flex-container--direction-horizontal',
'dnb-flex-container--direction-vertical',
'dnb-flex-container--justify-flex-start',
'dnb-flex-container--align-baseline',
'dnb-flex-container--spacing-small',
Expand All @@ -291,7 +291,46 @@ describe('Radio group component', () => {
).toEqual([
'dnb-space',
'dnb-flex-container',
'dnb-flex-container--direction-horizontal',
'dnb-flex-container--direction-vertical',
'dnb-flex-container--justify-flex-start',
'dnb-flex-container--align-baseline',
'dnb-flex-container--spacing-small',
'dnb-flex-container--wrap',
'dnb-flex-container--divider-space',
])
})

it('should support vertical label', () => {
const { rerender } = render(
<Radio.Group label="Label" vertical>
<Radio />
</Radio.Group>
)

const element = document.querySelector('.dnb-radio-group')
const flexElement = element.querySelector('.dnb-flex-container')

expect(Array.from(flexElement.classList)).toEqual([
'dnb-space',
'dnb-flex-container',
'dnb-flex-container--direction-vertical',
'dnb-flex-container--justify-flex-start',
'dnb-flex-container--align-baseline',
'dnb-flex-container--spacing-x-small',
'dnb-flex-container--wrap',
'dnb-flex-container--divider-space',
])

rerender(
<Radio.Group label="Label" label_direction="vertical">
<Radio />
</Radio.Group>
)

expect(Array.from(flexElement.classList)).toEqual([
'dnb-space',
'dnb-flex-container',
'dnb-flex-container--direction-vertical',
'dnb-flex-container--justify-flex-start',
'dnb-flex-container--align-baseline',
'dnb-flex-container--spacing-small',
Expand All @@ -300,6 +339,7 @@ describe('Radio group component', () => {
])
})
})

describe('Radio ARIA', () => {
it('should validate with ARIA rules for Radio', async () => {
const Comp = render(<Radio {...props} />)
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.
Original file line number Diff line number Diff line change
Expand Up @@ -294,14 +294,17 @@ export default class ToggleButtonGroup extends React.PureComponent {
<fieldset>
<Flex.Container
align="baseline"
direction={vertical ? 'vertical' : 'horizontal'}
direction={
vertical || label_direction === 'vertical'
? 'vertical'
: 'horizontal'
}
spacing={vertical ? 'x-small' : undefined}
>
<FormLabel
element="legend"
label_id={id + '-label'}
label_direction={label_direction}
label_sr_only={label_sr_only}
id={id + '-label'}
srOnly={label_sr_only}
>
{label}
</FormLabel>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,45 @@ describe('ToggleButton component', () => {
})

describe('ToggleButton group component', () => {
it('should support vertical label', () => {
const { rerender } = render(
<ToggleButton.Group label="Label" vertical>
<ToggleButton />
</ToggleButton.Group>
)

const element = document.querySelector('.dnb-toggle-button-group')
const flexElement = element.querySelector('.dnb-flex-container')

expect(Array.from(flexElement.classList)).toEqual([
'dnb-space',
'dnb-flex-container',
'dnb-flex-container--direction-vertical',
'dnb-flex-container--justify-flex-start',
'dnb-flex-container--align-baseline',
'dnb-flex-container--spacing-x-small',
'dnb-flex-container--wrap',
'dnb-flex-container--divider-space',
])

rerender(
<ToggleButton.Group label="Label" label_direction="vertical">
<ToggleButton />
</ToggleButton.Group>
)

expect(Array.from(flexElement.classList)).toEqual([
'dnb-space',
'dnb-flex-container',
'dnb-flex-container--direction-vertical',
'dnb-flex-container--justify-flex-start',
'dnb-flex-container--align-baseline',
'dnb-flex-container--spacing-small',
'dnb-flex-container--wrap',
'dnb-flex-container--divider-space',
])
})

it('has to have variant="radio', () => {
render(
<ToggleButton.Group label="Label" id="group">
Expand Down Expand Up @@ -630,7 +669,7 @@ describe('ToggleButton group component', () => {
).toEqual([
'dnb-space',
'dnb-flex-container',
'dnb-flex-container--direction-horizontal',
'dnb-flex-container--direction-vertical',
'dnb-flex-container--justify-flex-start',
'dnb-flex-container--align-baseline',
'dnb-flex-container--spacing-small',
Expand All @@ -642,7 +681,7 @@ describe('ToggleButton group component', () => {
).toEqual([
'dnb-space',
'dnb-flex-container',
'dnb-flex-container--direction-horizontal',
'dnb-flex-container--direction-vertical',
'dnb-flex-container--justify-flex-start',
'dnb-flex-container--align-baseline',
'dnb-flex-container--spacing-small',
Expand Down
Loading