Skip to content
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

fix(selectInput): temporary fix for select input with placeholder #1302

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
6 changes: 5 additions & 1 deletion packages/fuselage/src/components/SelectInput/SelectInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@ export const SelectInput = forwardRef(function SelectInput(
{ children, multiple, placeholder, onChange, ...props }: SelectInputProps,
ref: Ref<HTMLElement>
) {
const [isOptionSelected, setOptionSelected] = useState(false);
const [isPlaceholderVisible, setPlaceholderVisible] = useState(
!props.value && !props.defaultValue
);
const handleChange = useCallback(
(event) => {
if (event.currentTarget.value !== '') setOptionSelected(true);
console.log('event', event.currentTarget.value);
setPlaceholderVisible(!event.currentTarget.value);
onChange?.call(event.currentTarget, event);
},
Expand All @@ -40,6 +43,7 @@ export const SelectInput = forwardRef(function SelectInput(
);
}

console.log('props', isOptionSelected);
return (
<InputBox
placeholderVisible={isPlaceholderVisible ? !!placeholder : undefined}
Expand All @@ -49,7 +53,7 @@ export const SelectInput = forwardRef(function SelectInput(
type='select'
onChange={handleChange}
>
{placeholder && (
{placeholder && !isOptionSelected && (
<InputBox.Placeholder value=''>{placeholder}</InputBox.Placeholder>
)}
{children}
Expand Down