-
Notifications
You must be signed in to change notification settings - Fork 2
[#44] ✨ 공통 컴포넌트 RadioInput 컴포넌트 구현 #94
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d84fc51
[#44] 💄 Add custom radio input class styling
yongb2n 06bd589
[#44] ✨ Implement RadioInput component
yongb2n 5ffd324
[#44] ♻️ Add JSX.Element type
yongb2n 734112b
[#44] ✨ Create utility func for handling keydown events
yongb2n bea145c
[#44] ♻️ Refactor RadioInput for improved accessibility
yongb2n e43bf43
[#44] ✅ Add Storybook for RadioInput component
yongb2n File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| import clsx from 'clsx' | ||
|
|
||
| import { handleKeyDown } from '@/utils/handleKeyDown' | ||
|
|
||
| interface RadioInputProps extends React.InputHTMLAttributes<HTMLInputElement> { | ||
| label: string | ||
| } | ||
|
|
||
| export const RadioInput = ({ | ||
| label, | ||
| className = '', | ||
| checked, | ||
| disabled, | ||
| onChange, | ||
| ...props | ||
| }: RadioInputProps): JSX.Element => { | ||
| const labelClass = clsx( | ||
| 'flex cursor-pointer items-center', | ||
| disabled && 'cursor-not-allowed opacity-50', | ||
| className | ||
| ) | ||
|
|
||
| return ( | ||
| <label className={labelClass}> | ||
| <input type='radio' checked={checked} disabled={disabled} {...props} /> | ||
| <span | ||
| role='radio' | ||
| tabIndex={0} | ||
| aria-checked={checked} | ||
| aria-label={'radio button'} | ||
| onKeyDown={e => | ||
| handleKeyDown( | ||
| e, | ||
| () => | ||
| onChange?.({ | ||
| target: { checked: true, value: props.value }, | ||
| } as any), | ||
| disabled | ||
| ) | ||
| } | ||
| className='custom-radio' | ||
| /> | ||
| <span className='text-body-2 ml-4 h-22 font-normal text-gray-800'> | ||
| {label} | ||
| </span> | ||
| </label> | ||
| ) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import { fn } from '@storybook/test' | ||
|
|
||
| import { RadioInput } from '@/components/common/input/RadioInput' | ||
|
|
||
| export default { | ||
| title: 'Common/Input/RadioInput', | ||
| component: RadioInput, | ||
| parameters: { | ||
| layout: 'centered', | ||
| }, | ||
| tags: ['common', 'radio'], | ||
| args: { | ||
| onChange: fn(), | ||
| }, | ||
| } | ||
|
|
||
| export const Default = { | ||
| args: { | ||
| label: '회사 ‧ 학교', | ||
| }, | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| export const handleKeyDown = ( | ||
| e: React.KeyboardEvent, | ||
| callback: () => void, | ||
| disabled?: boolean | ||
| ): void => { | ||
| if (e.key === 'Enter' && !disabled) { | ||
| callback() | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 으로 하면서, 접근성 면에서 손해를 보는 현상이 있는거 같아요. 해당 아티클 참고하면 좋을거 같습니다 !