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

issue 329 inputMode in grid #332

Open
wants to merge 2 commits into
base: next
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion src/components/Edit/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,8 @@ const Edit = ({
const selectedDate = dayjs(event.target.value).format(ShortDate);
let value = calculateDaysFromDate(event.target.value) + 1;
setInputValue(selectedDate);
setEmitValue(value);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See https://github.com/Dyalog/ewc-client/pull/330/files . When we do a WG for Value we want the days, and for Text we want the literal text.

// setEmitValue(value);
setEmitValue(selectedDate);
};

return (
Expand Down
31 changes: 26 additions & 5 deletions src/components/Grid/GridEdit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useAppData } from '../../hooks';
import { calculateDateAfterDays, getObjectById, calculateDaysFromDate, handleMouseDown, handleMouseUp, handleMouseEnter, handleMouseMove, handleMouseLeave, handleMouseWheel, handleMouseDoubleClick, checkNumericType } from '../../utils';
import dayjs from 'dayjs';

const GridEdit = ({ data }) => {
const GridEdit = ({ data,onKeyDown1 }) => {
// console.log("grid data", {data})
const inputRef = useRef(null);
const dateRef = useRef(null);
Expand Down Expand Up @@ -126,6 +126,26 @@ const GridEdit = ({ data }) => {
// setStartIndex(start);
// setEndIndex(end);
};
const handleKeyDown = (event) => {
event.stopPropagation();
// console.log("Key down event triggered:", event.target, { event });

const input = event.target;
const start = input.selectionStart;
const end = input.selectionEnd;

if (start !== end) {
const selectedText = input.value.substring(start, end);
console.log("Selected text is:", selectedText);
if(onKeyDown1)
{
onKeyDown1(event);
}
} else {
handleKeyPress(event);
}
};


const handleDivSelect = () => {
const selection = window.getSelection();
Expand Down Expand Up @@ -590,10 +610,11 @@ const GridEdit = ({ data }) => {
// setIsEditable(true);
}}
value={inputValue}
onKeyDown={(e) => {
e.stopPropagation();
handleKeyPress(e);
}}
// onKeyDown={(e) => {
// e.stopPropagation();
// handleKeyPress(e);
// }}
onKeyDown={handleKeyDown}
onChange={(e) => {
e.stopPropagation();
setInputValue(e.target.value);
Expand Down
7 changes: 5 additions & 2 deletions src/components/Grid/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ import GridCell from "./GridCell";
import Header from "./Header";
import GridLabel from "./GridLabel";

const Component = ({ data }) => {
if (data?.type == "Edit") return <GridEdit data={data} />;

const Component = ({ data, onKeyDown1 }) => {
if (data?.type == "Edit") return <GridEdit data={data} onKeyDown1={onKeyDown1} />;
else if (data?.type == "Button") return <GridButton data={data} />;
else if (data?.type == "cell" || data?.type == "rowTitle") return <GridCell data={data} />;
else if (data?.type == "header") return <Header data={data} />;
Expand Down Expand Up @@ -716,6 +717,8 @@ const Grid = ({ data }) => {
focused: isFocused,
backgroundColor: data?.backgroundColor,
}}
onKeyDown1={handleKeyDown}

/>
</div>
);
Expand Down