Skip to content

Commit

Permalink
feat(Select): select the editable cell value on focus (#35)
Browse files Browse the repository at this point in the history
* feat(Select): select the editable cell value on focus

* chore(versions): upgrade version
  • Loading branch information
amen-souissi authored Nov 3, 2020
1 parent 0cf6a54 commit b880812
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@decathlon/react-table",
"version": "1.14.2",
"version": "1.15.0",
"description": "React components for efficiently rendering large tabular data",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
6 changes: 5 additions & 1 deletion src/components/styled-table/editable-cell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ export default class EdiTableCell extends React.PureComponent<IEdiTableCellProps
return [false, newValue];
};

private selectValue = (event: React.MouseEvent<HTMLInputElement, MouseEvent>) => {
event.currentTarget.select();
};

private focus = () => {
const { value } = this.props;
const newInputValue = this.getInputValue();
Expand Down Expand Up @@ -190,7 +194,7 @@ export default class EdiTableCell extends React.PureComponent<IEdiTableCellProps
thousandSeparator=" "
decimalSeparator=","
style={{ width: inputValueWidth }}
InputProps={{ classes: { underline: "editable-cell__underline" } }}
InputProps={{ classes: { underline: "editable-cell__underline" }, onFocus: this.selectValue }}
isNumericString
decimalScale={mask.decimals}
allowNegative={mask.is_negative}
Expand Down
8 changes: 2 additions & 6 deletions stories/components/styled-table/editable-cell.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import Table from "../../../src/components/table/table";
import { IContentCellProps } from "../../../src/components/table/cell";
import { getTable } from "./tables";
import { Nullable } from "../../../src/components/typing";
import { SelectionMenu } from "../../stories-components/selection-menu";

interface IProps extends IContentCellProps {
defaultValue: number;
Expand All @@ -21,7 +20,7 @@ interface IProps extends IContentCellProps {

const mask: IMask = {
is_percentage: false,
is_negative: false,
is_negative: true,
decimals: 2
};

Expand Down Expand Up @@ -128,10 +127,7 @@ storiesOf("Styled Table/editable cell", module)
{...defaultProps}
columns={{ 0: { style: { justifyContent: "left" } } }}
isVirtualized
isSelectable
selectionProps={{
menuComponent: SelectionMenu
}}
isSelectable={false}
virtualizerProps={{
fixedRows: object("fixedRows", [0]),
fixedColumns: object("fixedColumns", [0]),
Expand Down

0 comments on commit b880812

Please sign in to comment.