Skip to content
This repository has been archived by the owner on Jun 5, 2024. It is now read-only.

Commit

Permalink
fix: Textfield correction (#87)
Browse files Browse the repository at this point in the history
* fix: use alt ref prop name approach (`inputRef`)

- correct typedefs

* chore: release
  • Loading branch information
Jaeho Lee authored and Jaeho Lee committed Dec 7, 2022
1 parent b88bf7e commit c2d95bd
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 17 deletions.
6 changes: 6 additions & 0 deletions .changeset/clean-geese-invent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@greenlabs/formula-components": patch
"@greenlabs/rescript-formula-components": patch
---

TextField: use alt ref prop name approach (`inputRef`)
6 changes: 3 additions & 3 deletions packages/components-rescript/__tests__/Formula_test.res
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ let testTextField = () => {
}}
/>
<TextField prefixIcon={Icon.ArrowDownLineBold.make} suffixIcon={Icon.ArrowDownLineBold.make} />
<TextField tag="textarea" />
<TextField inputTag="textarea" />
<TextField
container={({?onChange, id, className}) => {
<input ?onChange id className />
inputContainer={({?onChange, id, className, inputRef}) => {
<input ?onChange id className ref={inputRef} />
}}
/>
</>
Expand Down
5 changes: 3 additions & 2 deletions packages/components-rescript/src/Formula__TextField.res
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
type textFieldComponentProps<'a> = {
id: string,
className: string,
inputRef: ReactDOM.domRef,
_type: [#text | #password],
props?: 'a,
name?: string,
Expand All @@ -15,8 +16,8 @@ type textFieldComponentProps<'a> = {
external make: (
~props: {..}=?,
~name: string=?,
~tag: string=?,
~container: React.componentLike<textFieldComponentProps<{..}>, React.element>=?,
~inputTag: string=?,
~inputContainer: React.componentLike<textFieldComponentProps<{..}>, React.element>=?,
~className: string=?,
~variant: [#boxOutline | #boxFill | #line]=?,
~size: [#xsmall | #samll | #medium | #large]=?,
Expand Down
18 changes: 15 additions & 3 deletions packages/components/src/TextField/TextField.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as React from "react"
import type { ComponentMeta, ComponentStory } from "@storybook/react"
import TextAreaAutosize from "react-textarea-autosize"

import type { inputContainerProps, InputElement } from "./TextField"
import { TextField } from "./TextField"
import { SearchLineBold, EyeLineBold } from "../Icon"
import { createDisabledArgs } from "../utils/storybook"
Expand Down Expand Up @@ -170,6 +171,19 @@ export const Textarea_and_Ref: ComponentStory<typeof TextField> = (args) => {
}
})

const inputContainer = React.memo(
React.forwardRef<InputElement, inputContainerProps>(
({ type, ...props }, ref) => {
return (
<TextAreaAutosize
ref={ref as React.ForwardedRef<HTMLTextAreaElement>}
{...props}
/>
)
}
)
)

return (
<ThemeScope
render={({ className }) => (
Expand All @@ -189,9 +203,7 @@ export const Textarea_and_Ref: ComponentStory<typeof TextField> = (args) => {
<TextField
{...args}
titleText="using `react-textarea-autosize` as `inputContainer`"
inputContainer={({ ...props }) => {
return <TextAreaAutosize {...props} />
}}
inputContainer={inputContainer}
/>
</form>
)}
Expand Down
19 changes: 10 additions & 9 deletions packages/components/src/TextField/TextField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { COMPONENT_CLASS, stateClass } from "./common"

type sizeVariantKey = keyof typeof textFieldSizeVariants
type variantKey = keyof typeof textFieldVariants
type InputElement = HTMLInputElement | HTMLTextAreaElement
export type InputElement = HTMLInputElement | HTMLTextAreaElement
type InputRefType = React.Ref<HTMLInputElement> & React.Ref<HTMLTextAreaElement>

type inputProps = {
Expand All @@ -36,18 +36,18 @@ type inputProps = {
type?: "text" | "password"
}

// FIXME: make input/textarea compatible
export type inputContainerProps = inputProps & {
id: string
className: string
type: "text" | "password" // FIXME: fix case for <textarea />
inputRef: InputRefType
}
type TextFieldProps = PropsWithChildren<
inputProps & {
id?: string
className?: string
inputContainer?: React.ComponentType<
inputProps & {
id: string
className: string
type: "text" | "password" // FIXME: fix case for <textarea />
ref: InputRefType
}
> // FIXME: add correct dom props type
inputContainer?: React.ComponentType<inputContainerProps>
inputTag?: "input" | "textarea"
size?: sizeVariantKey
variant?: "boxOutline" | "boxFill" | "line"
Expand Down Expand Up @@ -154,6 +154,7 @@ export const TextField = React.forwardRef<InputElement, TextFieldProps>(
<InputContainer
id={id ?? innerId}
ref={inputRef}
inputRef={inputRef}
name={name}
type={type}
onChange={onChange}
Expand Down

0 comments on commit c2d95bd

Please sign in to comment.