Skip to content

Commit

Permalink
Merge pull request #2035 from SpareBank1/Tooltip-legend-uu-fix
Browse files Browse the repository at this point in the history
fix(ffe-form-react): Fikse div med tooltip inne i fieldset legend
  • Loading branch information
tuva-odegard authored May 24, 2024
2 parents d4c50d1 + fc9559e commit f7c8549
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/ffe-form-react/src/RadioButtonInputGroup.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe('<RadioButtonInputGroup />', () => {
const { container } = renderRadioButtonInputGroup({
label: 'Test label',
});
const legend = container.querySelector('legend');
const legend = container.querySelector('.ffe-form-label');
expect(legend?.textContent).toBe('Test label');
});
it('does not render a legend if not set', () => {
Expand Down
10 changes: 7 additions & 3 deletions packages/ffe-form-react/src/RadioButtonInputGroup.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React from 'react';
import React, { useRef } from 'react';
import classNames from 'classnames';
import { ErrorFieldMessage } from './message';
import { Tooltip } from './Tooltip';
import { v4 as uuid } from 'uuid';

export interface RadioButtonInputGroupProps
extends Omit<
Expand Down Expand Up @@ -73,9 +74,11 @@ export const RadioButtonInputGroup: React.FC<RadioButtonInputGroupProps> = ({
'Don\'t use both "tooltip" and "description" on an <RadioButtonInputGroup />, pick one of them',
);
}
const id = useRef(uuid()).current;

return (
<fieldset
aria-labelledby={id}
className={classNames(
'ffe-input-group',
{ 'ffe-input-group--no-extra-margin': !extraMargin },
Expand All @@ -85,7 +88,8 @@ export const RadioButtonInputGroup: React.FC<RadioButtonInputGroupProps> = ({
{...rest}
>
{label && (
<legend
<div
id={id}
className={classNames(
'ffe-form-label',
'ffe-form-label--block',
Expand All @@ -96,7 +100,7 @@ export const RadioButtonInputGroup: React.FC<RadioButtonInputGroupProps> = ({
<Tooltip>{tooltip}</Tooltip>
)}
{React.isValidElement(tooltip) && tooltip}
</legend>
</div>
)}

{typeof description === 'string' ? (
Expand Down

0 comments on commit f7c8549

Please sign in to comment.