mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-12-05 06:09:57 -05:00
Select an item's value when its cell is clicked for editing
Clicking a cell in the Items table now focuses that field's input and selects its contents, so the user can type a replacement value immediately. FieldCell gains an `autoFocus` prop (focus + select on mount via a merged ref that still supports the draft row's first-field ref); InventoryTable tracks which cell was clicked and flags the matching FieldCell. Also add a FieldSchemaEditor test covering the select-options comma fix. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
6dd8e43635
commit
447e4a40df
4 changed files with 102 additions and 8 deletions
35
app/src/components/inventory/FieldSchemaEditor.test.js
Normal file
35
app/src/components/inventory/FieldSchemaEditor.test.js
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
import React from "react";
|
||||
import {fireEvent, render, screen} from "@testing-library/react";
|
||||
import {FieldSchemaEditor} from "./FieldSchemaEditor";
|
||||
|
||||
const FIELDS = [
|
||||
{key: 'name', label: 'Name', type: 'text', order: 0},
|
||||
{key: 'category', label: 'Category', type: 'select', options: [], order: 1},
|
||||
];
|
||||
|
||||
describe('FieldSchemaEditor select options', () => {
|
||||
test('typing a comma is preserved while editing (does not get swallowed)', () => {
|
||||
render(<FieldSchemaEditor fields={FIELDS} open={true} onClose={jest.fn()} onSave={jest.fn()}/>);
|
||||
const optionsInput = screen.getByPlaceholderText('comma,separated,options');
|
||||
|
||||
// Typing the comma after the first option must not be stripped — otherwise a second option can't be started.
|
||||
fireEvent.change(optionsInput, {target: {value: 'screws,'}});
|
||||
expect(optionsInput.value).toBe('screws,');
|
||||
|
||||
fireEvent.change(optionsInput, {target: {value: 'screws,nails'}});
|
||||
expect(optionsInput.value).toBe('screws,nails');
|
||||
});
|
||||
|
||||
test('options are trimmed and emptied-out on save', async () => {
|
||||
const onSave = jest.fn();
|
||||
render(<FieldSchemaEditor fields={FIELDS} open={true} onClose={jest.fn()} onSave={onSave}/>);
|
||||
const optionsInput = screen.getByPlaceholderText('comma,separated,options');
|
||||
|
||||
fireEvent.change(optionsInput, {target: {value: 'screws, nails ,'}});
|
||||
fireEvent.click(screen.getByText('Save Fields'));
|
||||
|
||||
const savedFields = onSave.mock.calls[0][0];
|
||||
const category = savedFields.find(f => f.key === 'category');
|
||||
expect(category.options).toEqual(['screws', 'nails']);
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue