mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-28 07:30:04 +00:00
fix(native): an entry field pushed under the open keyboard by a new row comes back above it
The packing list keeps its entry field open after Enter, and each added item lands above it. With the keyboard already up no keyboard event fires, so the field slid under the keyboard after the first entry. While the keyboard is up, a change to the page now checks the focused field again, once a frame at most.
This commit is contained in:
@@ -83,4 +83,39 @@ describe('keepFieldInView', () => {
|
||||
expect(addListener).toHaveBeenCalledWith('keyboardDidShow', expect.any(Function));
|
||||
expect(addListener).toHaveBeenCalledWith('keyboardWillHide', expect.any(Function));
|
||||
});
|
||||
|
||||
it('FE-NATIVE-KBFIELD-005: a field pushed under the open keyboard by a new row above it comes back up, and stops being watched once the keyboard goes', async () => {
|
||||
// The packing list keeps its entry field open after Enter: each added item lands above it.
|
||||
Object.defineProperty(window, 'innerHeight', { configurable: true, value: 1000 });
|
||||
const handlers: Record<string, (info?: { keyboardHeight: number }) => void> = {};
|
||||
const addListener = vi.fn(async (event: string, listener: (info?: { keyboardHeight: number }) => void) => {
|
||||
handlers[event] = listener;
|
||||
return { remove: vi.fn() };
|
||||
});
|
||||
keepFieldInView({ addListener } as never);
|
||||
const nextFrame = () => new Promise((resolve) => requestAnimationFrame(resolve));
|
||||
|
||||
const scroller = pane();
|
||||
const list = document.createElement('div');
|
||||
scroller.appendChild(list);
|
||||
const input = field(scroller, 'input', 600, 640);
|
||||
handlers.keyboardDidShow({ keyboardHeight: KEYBOARD });
|
||||
expect(scroller.scrollBy).not.toHaveBeenCalled();
|
||||
|
||||
// A new row pushes the field to 700..740, under the keyboard's top edge at 700.
|
||||
input.getBoundingClientRect = () => ({ top: 700, bottom: 740 }) as DOMRect;
|
||||
list.appendChild(document.createElement('div'));
|
||||
list.appendChild(document.createElement('div'));
|
||||
await nextFrame();
|
||||
await nextFrame();
|
||||
expect(scroller.scrollBy).toHaveBeenCalledTimes(1);
|
||||
expect(scroller.scrollBy).toHaveBeenCalledWith({ top: 740 - (700 - 24), behavior: 'smooth' });
|
||||
|
||||
handlers.keyboardWillHide();
|
||||
list.appendChild(document.createElement('div'));
|
||||
await nextFrame();
|
||||
await nextFrame();
|
||||
expect(scroller.scrollBy).toHaveBeenCalledTimes(1);
|
||||
expect(scroller.style.paddingBottom).toBe('');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user