-
Notifications
You must be signed in to change notification settings - Fork 1
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
웹 접근성 개선과 토스트 문서 추가 #86
Changes from 7 commits
ae949ff
f399b5a
8c2d264
0357c92
7a02be5
158ec78
17c3954
f1414ff
ae3791b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,10 @@ import { forwardRef } from 'react'; | |
import type { CSSProperties, ComponentPropsWithRef } from 'react'; | ||
import styled from 'styled-components'; | ||
|
||
import useValidator from '../hooks/useSpaceValidator'; | ||
import theme from '../styles/theme'; | ||
import Text from '../Text/Text'; | ||
|
||
export interface TextareaProps extends ComponentPropsWithRef<'textarea'> { | ||
/** | ||
* Textarea 컴포넌트 사이즈 재조정 방향 설정입니다. | ||
|
@@ -10,14 +14,33 @@ export interface TextareaProps extends ComponentPropsWithRef<'textarea'> { | |
} | ||
|
||
const Textarea = ({ resize = 'both', ref, ...props }: TextareaProps) => { | ||
const { value, error, handleChange } = useValidator(); | ||
|
||
return ( | ||
<TextareaContainer ref={ref} resize={resize} autoCapitalize="off" autoCorrect="off" spellCheck="false" {...props} /> | ||
<> | ||
<TextareaContainer | ||
value={value} | ||
ref={ref} | ||
resize={resize} | ||
error={error} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이 친구랑 |
||
autoCapitalize="off" | ||
autoCorrect="off" | ||
spellCheck="false" | ||
onChange={handleChange} | ||
{...props} | ||
/> | ||
<Text size="xs" color={theme.colors.error} aria-live="assertive"> | ||
{error} | ||
</Text> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이 친구는 여기 남기고 |
||
</> | ||
); | ||
}; | ||
|
||
export default forwardRef(Textarea); | ||
|
||
type TextareaStyleProps = Pick<TextareaProps, 'resize'>; | ||
type TextareaStyleProps = Pick<TextareaProps, 'resize'> & { | ||
error: string; | ||
}; | ||
|
||
const TextareaContainer = styled.textarea<TextareaStyleProps>` | ||
width: 100%; | ||
|
@@ -27,7 +50,7 @@ const TextareaContainer = styled.textarea<TextareaStyleProps>` | |
border-radius: 0; | ||
line-height: 1.5; | ||
resize: ${({ resize }) => resize}; | ||
outline-color: ${({ theme }) => theme.colors.primary}; | ||
outline-color: ${({ error, theme }) => (error ? theme.colors.error : theme.colors.primary)}; | ||
|
||
&::placeholder { | ||
color: ${({ theme }) => theme.textColors.disabled}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,9 @@ const Toast = ({ id, message, isError = false }: ToastProps) => { | |
|
||
return ( | ||
<ToastWrapper isError={isError} isAnimating={isShown}> | ||
<Message color={theme.colors.white}>{message}</Message> | ||
<Message color={theme.colors.white} aria-live="assertive"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
{message} | ||
</Message> | ||
</ToastWrapper> | ||
); | ||
}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import type { ChangeEventHandler } from 'react'; | ||
import { useState } from 'react'; | ||
|
||
const useSpaceValidator = (initialValue = '') => { | ||
const [value, setValue] = useState(initialValue); | ||
const [error, setError] = useState(''); | ||
|
||
const handleChange: ChangeEventHandler<HTMLTextAreaElement> = (e) => { | ||
const newValue = e.target.value; | ||
setValue(newValue); | ||
|
||
const isWhitespaceOnly = !newValue.trim() && newValue.length > 2; | ||
const isConsecutiveSpaces = /\s{10,}/.test(newValue); | ||
const isConsecutiveNewlines = /\n{4,}/.test(newValue); | ||
|
||
isWhitespaceOnly || isConsecutiveSpaces || isConsecutiveNewlines | ||
? setError('의미 있는 리뷰를 작성해보는 건 어떨까요? 🫨') | ||
: setError(''); | ||
}; | ||
|
||
return { value, error, handleChange }; | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이 훅은 사용처에서 작성해도 될거 같아요. |
||
|
||
export default useSpaceValidator; |
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.
그럼 요거가 삭제되겠네요!