Skip to content

Commit

Permalink
fix: Edit 한국어 maxLength 이상으로 쳐지는 이슈 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
shinhyojeong committed Jan 31, 2024
1 parent 078875b commit af15f31
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion packages/react/src/components/Input/Edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { ColorKeys } from '@offer-ui/themes'
import type { StyledProps } from '@offer-ui/types'
import { convertToNumber, toLocaleCurrency } from '@offer-ui/utils/format'
import { forwardRef } from 'react'
import type { ChangeEventHandler, ForwardedRef } from 'react'
import type { ChangeEventHandler, FormEventHandler, ForwardedRef } from 'react'
import type { InputProps } from './index'

export type EditInputProps = InputProps & {
Expand Down Expand Up @@ -46,6 +46,8 @@ export const Edit = forwardRef(function Edit(
width = '100%',
onChange,
isPrice = false,
maxLength,
onInput,
...props
}: EditInputProps,
ref: ForwardedRef<HTMLInputElement>
Expand All @@ -63,6 +65,16 @@ export const Edit = forwardRef(function Edit(
onChange?.(e)
}

const handleInput: FormEventHandler<HTMLInputElement> = (e): void => {
const inputValue = e.currentTarget.value

if (maxLength && maxLength < inputValue.length) {
e.currentTarget.value = inputValue.slice(0, maxLength)
}

onInput?.(e)
}

return (
<StyledInputForm width={width}>
<StyledInputLabel>
Expand All @@ -71,7 +83,9 @@ export const Edit = forwardRef(function Edit(
ref={ref}
hasGuideMessage={hasGuideMessage}
isSmall={isSmall}
maxLength={maxLength}
onChange={handleChange}
onInput={handleInput}
{...props}
/>
{isPrice && (
Expand Down

0 comments on commit af15f31

Please sign in to comment.