Skip to content
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
65 changes: 34 additions & 31 deletions js/dataframe/cell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -332,25 +332,25 @@ export const TableBodyCell: FC<TableBodyCellProps> = ({
setValue(e.target.value);
}

// https://medium.com/@oherterich/creating-a-textarea-with-dynamic-height-using-react-and-typescript-5ed2d78d9848
// Updates the height of a <textarea> when the value changes.
const useAutosizeTextArea = (
textAreaRef: HTMLTextAreaElement | null,
value: string
) => {
useEffect(() => {
if (textAreaRef) {
// We need to reset the height momentarily to get the correct scrollHeight for the textarea
textAreaRef.style.height = "0px";
const scrollHeight = textAreaRef.scrollHeight;

// We then set the height directly, outside of the render loop
// Trying to set this with state or a ref will product an incorrect value.
textAreaRef.style.height = scrollHeight + "px";
}
}, [textAreaRef, value]);
};
useAutosizeTextArea(inputRef.current, value as string);
// // https://medium.com/@oherterich/creating-a-textarea-with-dynamic-height-using-react-and-typescript-5ed2d78d9848
// // Updates the height of a <textarea> when the value changes.
// const useAutosizeTextArea = (
// textAreaRef: HTMLTextAreaElement | null,
// value: string
// ) => {
// useEffect(() => {
// if (textAreaRef) {
// // We need to reset the height momentarily to get the correct scrollHeight for the textarea
// textAreaRef.style.height = "0px";
// const scrollHeight = textAreaRef.scrollHeight;

// // We then set the height directly, outside of the render loop
// // Trying to set this with state or a ref will product an incorrect value.
// textAreaRef.style.height = scrollHeight + "px";
// }
// }, [textAreaRef, value]);
// };
// useAutosizeTextArea(inputRef.current, value as string);

let onClick:
| ((e: ReactMouseEvent<HTMLTableCellElement>) => void)
Expand All @@ -361,21 +361,23 @@ export const TableBodyCell: FC<TableBodyCellProps> = ({
const tableCellClass = CellStateClassEnum[cellState];
// let cellContentEditable: boolean = false;

let editContent: ReactElement | null = null;
if (cellState === CellStateEnum.EditSaving) {
content = <em>{value as string}</em>;
} else if (cellState === CellStateEnum.Editing) {
content = (
<textarea
value={value as string}
onChange={onChange}
// onBlur={onBlur}
onFocus={onFocus}
onKeyDown={onInputKeyDown}
ref={inputRef}
style={{ width: "100%", height: "100%" }}
/>
);
} else {
if (cellState === CellStateEnum.Editing) {
editContent = (
<textarea
value={value as string}
onChange={onChange}
// onBlur={onBlur}
onFocus={onFocus}
onKeyDown={onInputKeyDown}
ref={inputRef}
// style={{ width: "100%", height: "100%" }}
/>
);
}
// Only allow transition to edit mode if the cell can be edited
if (editCellsIsAllowed) {
onClick = (e: ReactMouseEvent<HTMLTableCellElement>) => {
Expand Down Expand Up @@ -419,6 +421,7 @@ export const TableBodyCell: FC<TableBodyCellProps> = ({
title={cellTitle}
className={tableCellClass}
>
{editContent}
{content}
</td>
);
Expand Down
24 changes: 19 additions & 5 deletions js/dataframe/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -273,13 +273,27 @@ shiny-data-frame {
* # CELL EDITING STYLES
*
*/
shiny-data-frame .shiny-data-grid > table > tbody > tr > td:has(> textarea.cell-edit-editing) {
padding: 0;
margin: 0;
shiny-data-frame .shiny-data-grid > table > tbody > tr > td.cell-edit-editing {
// padding: 0;
// margin: 0;

:not(textarea) {
visibility: hidden;
}

color: transparent;

// Position the textarea over the existing cell via absolute positioning and inset
// Use absolute positioning to ensure the textarea is using the full available space!
position: relative;
& > textarea {
width: 100%;
height: 100%;
position: absolute;
inset: var(--shiny-datagrid-padding-x) var(--shiny-datagrid-padding-y);

background-color: inherit;
padding: 0px;
// overflow: hidden;
resize: none;
}
}

Expand Down
Loading