Skip to content

Commit

Permalink
#676 Fix cursor moves to end of input when typing in tables
Browse files Browse the repository at this point in the history
  • Loading branch information
Polleps committed Nov 1, 2023
1 parent 4e9553e commit f5cab1d
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 15 deletions.
14 changes: 3 additions & 11 deletions browser/data-browser/src/components/forms/InputBoolean.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React, { useState } from 'react';
import { useBoolean } from '@tomic/react';
import { InputProps } from './ResourceField';
import { ErrMessage, InputStyled } from './InputStyles';
import { ErrMessage } from './InputStyles';
import { Checkbox } from './Checkbox';

export default function InputBoolean({
resource,
Expand All @@ -15,18 +16,9 @@ export default function InputBoolean({
commit,
});

function handleUpdate(e: React.ChangeEvent<HTMLInputElement>) {
setValue(e.target.checked);
}

return (
<>
<InputStyled
type='checkbox'
checked={!!value}
onChange={handleUpdate}
{...props}
/>
<Checkbox checked={!!value} onChange={setValue} {...props} />
{err && <ErrMessage>{err.message}</ErrMessage>}
</>
);
Expand Down
4 changes: 3 additions & 1 deletion browser/data-browser/src/components/forms/InputNumber.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useState } from 'react';
import { useNumber } from '@tomic/react';
import { Datatype, useNumber } from '@tomic/react';
import { InputProps } from './ResourceField';
import { ErrMessage, InputStyled, InputWrapper } from './InputStyles';

Expand All @@ -12,6 +12,7 @@ export default function InputNumber({
const [err, setErr] = useState<Error | undefined>(undefined);
const [value, setValue] = useNumber(resource, property.subject, {
handleValidationError: setErr,
validate: false,
commit,
});

Expand All @@ -33,6 +34,7 @@ export default function InputNumber({
placeholder='Enter a number...'
type='number'
value={value === undefined ? '' : Number.isNaN(value) ? '' : value}
step={property.datatype === Datatype.INTEGER ? 1 : 'any'}
onChange={handleUpdate}
{...props}
/>
Expand Down
1 change: 1 addition & 0 deletions browser/data-browser/src/components/forms/InputSlug.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export default function InputSlug({

const [value, setValue] = useString(resource, property.subject, {
handleValidationError: setErr,
validate: false,
commit,
});

Expand Down
2 changes: 1 addition & 1 deletion browser/data-browser/src/components/forms/InputString.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ export default function InputString({
...props
}: InputProps): JSX.Element {
const [err, setErr, onBlur] = useValidation();

const [value, setValue] = useString(resource, property.subject, {
commit,
validate: false,
});

function handleUpdate(event: React.ChangeEvent<HTMLInputElement>): void {
Expand Down
5 changes: 3 additions & 2 deletions browser/data-browser/src/views/TablePage/TableCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ function useIsEditing(row: number, column: number) {
const valueOpts = {
commitDebounce: 0,
commit: false,
validate: false,
};

export function TableCell({
Expand Down Expand Up @@ -105,7 +106,7 @@ export function TableCell({

save();
},
[setValue, setCreatedAt, createdAt, value, resource, property],
[setValue, setCreatedAt, createdAt, resource, property, save],
);

const handleEnterEditModeWithCharacter = useCallback(
Expand Down Expand Up @@ -139,7 +140,7 @@ export function TableCell({
resource={resource}
/>
) : (
<React.Fragment key={`${value}`}>
<React.Fragment>
<Editor.Display
value={value}
onChange={onChange}
Expand Down

0 comments on commit f5cab1d

Please sign in to comment.