Skip to content

Commit

Permalink
Fix input fields for key-value pair tables losing focus
Browse files Browse the repository at this point in the history
  • Loading branch information
dstotijn committed Feb 26, 2022
1 parent 7e43479 commit d2858a2
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions admin/src/lib/components/KeyValuePair.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
Table,
TableBody,
TableCell,
TableCellProps,
TableContainer,
TableHead,
TableRow,
Expand Down Expand Up @@ -74,19 +73,6 @@ export function KeyValuePairTable({ items, onChange, onDelete }: KeyValuePairTab
setCopyConfOpen(false);
};

const baseCellStyle = {
"&:hover": {
cursor: "copy",
},
};

const KeyTableCell = styled(TableCell)<TableCellProps>(() => (!onChange ? baseCellStyle : {}));
const ValueTableCell = styled(TableCell)<TableCellProps>(() => ({
...(!onChange && baseCellStyle),
width: "60%",
wordBreak: "break-all",
}));

return (
<div>
<Snackbar open={copyConfOpen} autoHideDuration={3000} onClose={handleCopyConfClose}>
Expand Down Expand Up @@ -118,12 +104,19 @@ export function KeyValuePairTable({ items, onChange, onDelete }: KeyValuePairTab
>
{items.map(({ key, value }, idx) => (
<StyledTableRow key={idx} hover>
<KeyTableCell
<TableCell
component="th"
scope="row"
onClick={(e) => {
!onChange && handleCellClick(e);
}}
sx={{
...(!onChange && {
"&:hover": {
cursor: "copy",
},
}),
}}
>
{!onChange && <span>{key}</span>}
{onChange && (
Expand All @@ -137,11 +130,20 @@ export function KeyValuePairTable({ items, onChange, onDelete }: KeyValuePairTab
}}
/>
)}
</KeyTableCell>
<ValueTableCell
</TableCell>
<TableCell
onClick={(e) => {
!onChange && handleCellClick(e);
}}
sx={{
width: "60%",
wordBreak: "break-all",
...(!onChange && {
"&:hover": {
cursor: "copy",
},
}),
}}
>
{!onChange && value}
{onChange && (
Expand All @@ -155,7 +157,7 @@ export function KeyValuePairTable({ items, onChange, onDelete }: KeyValuePairTab
}}
/>
)}
</ValueTableCell>
</TableCell>
{onDelete && (
<TableCell>
<div className="delete-button">
Expand Down

0 comments on commit d2858a2

Please sign in to comment.