Skip to content

Commit c272dd1

Browse files
Revert "Vertically centre radio and checkbox properly"
This reverts commit d02e303.
1 parent 3ff3ceb commit c272dd1

File tree

3 files changed

+28
-29
lines changed

3 files changed

+28
-29
lines changed

app/forms/access-util.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ export function RoleRadioField<
106106
className="mt-2"
107107
>
108108
{R.reverse(allRoles).map((role) => (
109-
<Radio name="roleName" key={role} value={role}>
109+
<Radio name="roleName" key={role} value={role} alignTop>
110110
<div className="text-sans-md text-raise">
111111
{capitalize(role).replace('_', ' ')}
112112
</div>

app/ui/lib/Checkbox.tsx

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -46,24 +46,22 @@ export const Checkbox = ({
4646
className,
4747
...inputProps
4848
}: CheckboxProps) => (
49-
<label className="text-sans-md">
50-
<div className="inline-flex h-lh shrink-0 grow-0 items-center">
51-
<span className="relative h-4 w-4">
52-
<input
53-
className={cn(inputStyle, className)}
54-
type="checkbox"
55-
ref={(el) => {
56-
if (el) {
57-
el.indeterminate = !!indeterminate
58-
}
59-
}}
60-
{...inputProps}
61-
/>
62-
{inputProps.checked && !indeterminate && <Check />}
63-
{indeterminate && <Indeterminate />}
64-
</span>
49+
<label className="items-top inline-flex">
50+
<span className="relative h-4 w-4">
51+
<input
52+
className={cn(inputStyle, className)}
53+
type="checkbox"
54+
ref={(el) => {
55+
if (el) {
56+
el.indeterminate = !!indeterminate
57+
}
58+
}}
59+
{...inputProps}
60+
/>
61+
{inputProps.checked && !indeterminate && <Check />}
62+
{indeterminate && <Indeterminate />}
63+
</span>
6564

66-
{children && <span className="text-default ml-2.5">{children}</span>}
67-
</div>
65+
{children && <span className="text-sans-md text-default ml-2.5">{children}</span>}
6866
</label>
6967
)

app/ui/lib/Radio.tsx

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ import cn from 'classnames'
1717
import type { ComponentProps } from 'react'
1818

1919
// input type is fixed to "radio"
20-
export type RadioProps = Omit<React.ComponentProps<'input'>, 'type'>
20+
export type RadioProps = Omit<React.ComponentProps<'input'>, 'type'> & {
21+
/** Align radio button with top of content instead of center (useful for multi-line content) */
22+
alignTop?: boolean
23+
}
2124

2225
const fieldStyles = `
2326
peer appearance-none absolute outline-hidden
@@ -26,15 +29,13 @@ const fieldStyles = `
2629
disabled:hover:bg-transparent
2730
`
2831

29-
export const Radio = ({ children, className, ...inputProps }: RadioProps) => (
30-
<label className="text-sans-md flex">
31-
<div className="inline-flex h-lh shrink-0 grow-0 items-center">
32-
<span className="relative h-4 w-4 shrink-0">
33-
<input className={cn(fieldStyles, className)} type="radio" {...inputProps} />
34-
{/* the dot in the middle. hide by default, use peer-checked to show if checked */}
35-
<div className="bg-accent pointer-events-none absolute top-1 left-1 hidden h-2 w-2 rounded-full peer-checked:block" />
36-
</span>
37-
</div>
32+
export const Radio = ({ children, className, alignTop, ...inputProps }: RadioProps) => (
33+
<label className={cn('inline-flex', alignTop ? 'items-start' : 'items-center')}>
34+
<span className="relative h-4 w-4 shrink-0">
35+
<input className={cn(fieldStyles, className)} type="radio" {...inputProps} />
36+
{/* the dot in the middle. hide by default, use peer-checked to show if checked */}
37+
<div className="bg-accent pointer-events-none absolute top-1 left-1 hidden h-2 w-2 rounded-full peer-checked:block" />
38+
</span>
3839

3940
{children && <span className="text-default ml-2.5">{children}</span>}
4041
</label>

0 commit comments

Comments
 (0)