Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
29 changes: 29 additions & 0 deletions src/components/common/input/RadioInput.tsx
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://juhyejin.tistory.com/54

원래 input 의 display 를 none 으로 하면서, 접근성 면에서 손해를 보는 현상이 있는거 같아요. 해당 아티클 참고하면 좋을거 같습니다 !

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import clsx from 'clsx'

interface RadioInputProps extends React.InputHTMLAttributes<HTMLInputElement> {
label: string
}

export const RadioInput = ({
label,
className = '',
checked,
disabled,
...props
}: RadioInputProps): JSX.Element => {
return (
<label
className={clsx(
'flex cursor-pointer items-center',
disabled && 'cursor-not-allowed opacity-50',
className
)}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clsx 같은 경우에는,

const labelClass = clsx(
        'flex cursor-pointer items-center',
        disabled && 'cursor-not-allowed opacity-50',
        className
      )
      
      className={labelClass}

이런 식으로 return 부는 가능한 깔끔하게 남기면 좋을거 같아요 !

>
<input type='radio' checked={checked} disabled={disabled} {...props} />
<span className='custom-radio'></span>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

지금 이 cusom-raio 가 라디오 버튼을 대신해주고 있으니, aria 태그는 이 친구에게
aria-label={'radio button'} 주면 좋을거 같아요

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<span role="radio" tabindex="0" aria-checked={checked}></span>

추가로 줄 만한 속성이 role, tabindex, aira-checked 정도 있을 것 같아요

<span className='text-body-2 ml-4 h-22 font-normal leading-body2 text-gray-800'>
{label}
</span>
</label>
)
}
18 changes: 18 additions & 0 deletions src/styles/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,21 @@ select {
outline: 0;
cursor: pointer;
}

input[type='radio'] {
display: none;
}
.custom-radio {
@apply relative inline-block h-20 w-20 cursor-pointer rounded-full border-[1.4px] border-solid border-gray-300;
}
.custom-radio::before {
content: '';
@apply absolute left-1/2 top-1/2 block h-12 w-12 -translate-x-1/2 -translate-y-1/2 rounded-full;
}
input[type='radio']:checked + .custom-radio {
@apply border-primary-normal;
}

input[type='radio']:checked + .custom-radio::before {
@apply bg-primary-normal;
}