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

Create function of selection value in number-sells on first click #30

Open
wants to merge 16 commits into
base: develop
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
a95a963
Create function of selection value in number-sells on first click
dm-rybalchenko Dec 13, 2022
5d22b60
Added test for selectoin-function. Added unique id for every row and …
dm-rybalchenko Dec 17, 2022
85b800a
Added jsDoc, renamed and refactored function onClick, solved smell wi…
dm-rybalchenko Dec 18, 2022
170e1a4
Tabindexes are eplaced with id's. Writed new test for selecting text …
dm-rybalchenko Dec 18, 2022
0c252b9
#69 fix: Cell> Fixed problem with loosing focus after rerenders
dm-rybalchenko Dec 20, 2022
9af33f8
Merge branch 'develop' into feature/cells-text-selection
cybermerlin Dec 20, 2022
fe666c5
#69 fix: Cell,App,README> remove unnecessary code + reformat code by …
cybermerlin Dec 21, 2022
aa28fe5
#69 fix: Cell> fix selection text - now by focus instead of click
cybermerlin Dec 21, 2022
604fff3
Merge branch 'develop' into feature/cells-text-selection
cybermerlin Dec 22, 2022
54a66bb
#79 fix: jest,Cell> troubles with aliases (tsconfig) + jest coverage …
cybermerlin Dec 27, 2022
b699864
Merge branch 'develop' into feature/cells-text-selection
cybermerlin Dec 27, 2022
b7cc1eb
#81 fix: jest,repo,ci> fix troubles with enums + change CI services a…
cybermerlin Dec 27, 2022
86434fb
Merge branch 'develop' into feature/cells-text-selection
cybermerlin Dec 27, 2022
8000623
#70 fix: stories,sonar> cleanup + sonar manual configuring
cybermerlin Dec 28, 2022
3bcdc0f
add: docs.infrastructure.ServiceMesh
cybermerlin Dec 30, 2022
a19c01a
#81 fix: tests,utils> move out all tests into separated directory + a…
cybermerlin Dec 30, 2022
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
29 changes: 27 additions & 2 deletions src/lib/editableGrid/Cell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import PlusIcon from './img/Plus';
import type { CellProps, OptionsColumn } from './types/typesCell'
import { DATA_TYPES, EActionTypes, randomColor } from './utils';

let selectCell = 0;
cybermerlin marked this conversation as resolved.
Show resolved Hide resolved

export default function Cell({
value: initialValue,
Expand Down Expand Up @@ -79,8 +80,8 @@ export default function Cell({
/**
* This function is needed to prevent the saving of incomplete formulas (saves the last entered formula in the cell)
*/
function onBlur(e) {
let formula = findFormula(e.target.parentNode.tabIndex);
function onBlur(e: React.FocusEvent<Element>) {
let formula = findFormula((e.target.parentNode as HTMLElement).tabIndex);

if (formula) {
setValue({ value: formula.result, update: true });
Expand All @@ -90,6 +91,29 @@ export default function Cell({
}
}

/**
* This function is needed to select text in number-cells via first click on the cell
*/
function onClick(e: React.MouseEvent<Element>) {
cybermerlin marked this conversation as resolved.
Show resolved Hide resolved
if (e.target instanceof HTMLDivElement && e.detail === 1) {
cybermerlin marked this conversation as resolved.
Show resolved Hide resolved
cybermerlin marked this conversation as resolved.
Show resolved Hide resolved
let idCell = (e.target.parentNode as HTMLElement).tabIndex;
let selection = window.getSelection().toString();

if (selectCell !== idCell && !selection) {
let range = document.createRange();
let select = window.getSelection();

range.selectNodeContents(e.target);
select.removeAllRanges();
select.addRange(range);

} else if (selectCell !== idCell && selection) {
window.getSelection().removeAllRanges();
cybermerlin marked this conversation as resolved.
Show resolved Hide resolved
selectCell = idCell;
}
}
}

function handleOptionClick(option: OptionsColumn) {
setValue({ value: option.label, update: true });
setShowSelect(false);
Expand All @@ -110,6 +134,7 @@ export default function Cell({
return (
<ContentEditable
html={(value.value && value.value.toString()) || ''}
onClick={onClick}
onChange={onChange}
onBlur={onBlur}
className="data-input data-input-number text-align-right"
Expand Down