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: uncontrolled-input err, save and display empty string #155

Merged
merged 6 commits into from
Feb 7, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Bug fixes

- [#155](https://github.com/alleslabs/celatone-frontend/pull/155) Fix uncontrolled input error and fix space bar issue in editable cell
- [#137](https://github.com/alleslabs/celatone-frontend/pull/137) Throw error instead of returning undefined in query function
- [#148](https://github.com/alleslabs/celatone-frontend/pull/148) Fix scrolling to table header on first land
- [#146](https://github.com/alleslabs/celatone-frontend/pull/146) Fix contract select always fetch when theres no contract address, edit query keys
Expand Down
15 changes: 9 additions & 6 deletions src/lib/components/table/EditableCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface EditableCellProps {
onSave?: (value?: string) => void;
}
export const EditableCell = ({
initialValue,
initialValue = "",
defaultValue,
maxLength,
tooltip,
Expand Down Expand Up @@ -40,19 +40,22 @@ export const EditableCell = ({
};
const handleChange = (event: ChangeEvent<HTMLInputElement>) => {
const newVal = event.target.value;
setInputValue(newVal);
setInputValue(newVal.trimStart());
};
const handleCancel = () => {
setIsEdit(false);
setInputValue(initialValue);
};

const handleSave = () => {
setIsEdit(false);
onSave?.(inputValue);
};

// TODO: reconsider 20
const showName = isHoverText && (inputValue ?? "").length > 20;
const showName = isHoverText && inputValue.trim().length > 20;
const isShowInputValue = inputValue.trim().length;

return (
<Flex
gap={1}
Expand Down Expand Up @@ -104,10 +107,10 @@ export const EditableCell = ({
variant="body2"
className="ellipsis"
maxW="150px"
fontWeight={inputValue ? "600" : "400"}
color={inputValue ? "text.main" : "text.dark"}
fontWeight={isShowInputValue ? "600" : "400"}
color={isShowInputValue ? "text.main" : "text.dark"}
>
{inputValue ?? defaultValue}
{isShowInputValue ? inputValue : defaultValue}
</Text>
{showName && (
<Text
Expand Down