Skip to content

Commit

Permalink
Review afixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ogermain-kronos committed Jul 12, 2024
1 parent ecd820a commit 8826151
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ exports[`Radio button matches snapshot 1`] = `
margin: 0;
position: relative;
width: var(--size-1x);
-webkit-flex-shrink: 0;
-ms-flex-negative: 0;
flex-shrink: 0;
margin-top: var(--spacing-half);
}
.c1 + {
Expand Down Expand Up @@ -57,10 +61,10 @@ exports[`Radio button matches snapshot 1`] = `
}
.c0 {
-webkit-align-items: center;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
-webkit-align-items: flex-start;
-webkit-box-align: flex-start;
-ms-flex-align: flex-start;
align-items: flex-start;
display: -webkit-inline-box;
display: -webkit-inline-flex;
display: -ms-inline-flexbox;
Expand Down
17 changes: 4 additions & 13 deletions packages/react/src/components/radio-button/radio-button.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { ChangeEvent, FunctionComponent } from 'react';
import styled from 'styled-components';
import { focus } from '../../utils/css-state';
import { VisuallyHidden } from '../visually-hidden/visuallyhidden';
import { useId } from '../../hooks/use-id';

const StyledInput = styled.input<{ disabled?: boolean }>`
Expand All @@ -15,6 +14,8 @@ const StyledInput = styled.input<{ disabled?: boolean }>`
margin: 0;
position: relative;
width: var(--size-1x);
flex-shrink: 0;
margin-top: var(--spacing-half);
${(theme) => focus(theme, { selector: '+' })}
Expand Down Expand Up @@ -46,7 +47,7 @@ const StyledLabel = styled.label`
`;

const StyledContainer = styled.div`
align-items: center;
align-items: flex-start;
display: inline-flex;
margin-top: var(--spacing-1x);
position: relative;
Expand All @@ -59,12 +60,10 @@ interface RadioButtonProps {
className?: string;
defaultChecked?: boolean;
disabled?: boolean;
externalLabelId?: string;
id?: string;
label?: string;
name?: string;
value?: string;
visuallyHidden?: boolean;

onChange?(event: ChangeEvent<HTMLInputElement>): void;
}
Expand All @@ -76,18 +75,14 @@ export const RadioButton: FunctionComponent<RadioButtonProps> = ({
className,
defaultChecked,
disabled,
externalLabelId,
id,
label,
name,
value,
visuallyHidden,
onChange,
}) => {
const generatedId = useId();
const inputId = id || generatedId;
const externalLabel = externalLabelId ? document.getElementById(externalLabelId)?.innerText : '';
const inputLabel = externalLabelId ? `${label} ${externalLabel}` ?? '' : label;

return (
<StyledContainer>
Expand All @@ -111,11 +106,7 @@ export const RadioButton: FunctionComponent<RadioButtonProps> = ({
data-testid={`radiobutton-${inputId}_label`}
htmlFor={inputId}
>
{
visuallyHidden
? <VisuallyHidden>{inputLabel}</VisuallyHidden>
: inputLabel
}
{label}
</StyledLabel>
)
}
Expand Down
4 changes: 0 additions & 4 deletions packages/storybook/stories/radio-button.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ Radio buttons display mutually exclusive options from which a user selects exact
### Checked and disabled
<Canvas of={RadioButtonStories.CheckedAndDisabled}/>

### Labelling with text from another DOM element
<p hidden id="idPotato">Mr. Potato</p>
<Canvas of={RadioButtonStories.WithExternalLabel} />

## Properties
<ArgTypes of={RadioButton} />

Expand Down
7 changes: 0 additions & 7 deletions packages/storybook/stories/radio-button.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,6 @@ export const Default: Story = {
},
};

export const WithExternalLabel: Story = {
args: {
label: 'Merge contact: ',
externalLabelId: 'idPotato',
},
};

export const Checked: Story = {
args: {
label: 'Merge contact',
Expand Down

0 comments on commit 8826151

Please sign in to comment.