Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[PLAY-1237] Fix addon input child #3202

Merged
merged 2 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
14 changes: 9 additions & 5 deletions playbook/app/pb_kits/playbook/pb_text_input/_text_input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type TextInputProps = {
required?: boolean,
type: string,
value: string | number,
children: Node,
children: React.ReactElement,
addOn?: {
icon?: string,
alignment?: "right" | "left",
Expand Down Expand Up @@ -85,8 +85,12 @@ const TextInput = (props: TextInputProps, ref: React.LegacyRef<HTMLInputElement>
icon={icon}
/>
)

const childInput = children ? children.type === "input" : undefined

const textInput = (
<input
childInput ? React.cloneElement(children, { className: "text_input" }) :
(<input
{...domSafeProps(props)}
className="text_input"
disabled={disabled}
Expand All @@ -99,7 +103,7 @@ const TextInput = (props: TextInputProps, ref: React.LegacyRef<HTMLInputElement>
required={required}
type={type}
value={value}
/>
/>)
)

const addOnInput = (
Expand Down Expand Up @@ -131,7 +135,7 @@ const TextInput = (props: TextInputProps, ref: React.LegacyRef<HTMLInputElement>
)

const render = (() => {
if(children) return children
if (children && !childInput) return children
if (shouldShowAddOn) return addOnInput

return textInput
Expand All @@ -144,7 +148,7 @@ const TextInput = (props: TextInputProps, ref: React.LegacyRef<HTMLInputElement>
{...htmlProps}
className={css}
>
{label &&
{label &&
<Caption
className="pb_text_input_kit_label"
text={label}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ const TextInputAddOn = (props) => {
{...props}
/>
</div>
<div>
<TextInput
addOn={{ icon: 'frog', alignment: 'right', border: true }}
label="Right-Aligned Add On With Child Input"
onChange={handleUpdateFourthInput}
{...props}
>
<input />
</TextInput>
</div>
<div>
<TextInput
addOn={{ icon: 'percent', alignment: 'left', border: false }}
Expand All @@ -76,6 +86,16 @@ const TextInputAddOn = (props) => {
{...props}
/>
</div>
<div>
<TextInput
addOn={{ icon: 'frog', alignment: 'left', border: true }}
label="Left-Aligned Add On With Child Input"
onChange={handleUpdateFourthInput}
{...props}
>
<input />
</TextInput>
</div>
</>
)
}
Expand Down