Skip to content

A local-first personal finance app

fix mobile datepicker not opening (#9071)

Michael Clark5e39105f59aa
diff --git a/packages/desktop-client/src/components/mobile/MobileForms.test.tsx b/packages/desktop-client/src/components/mobile/MobileForms.test.tsx
new file mode 100644
index 0000000000..0d1f1e06c5
--- /dev/null
+++ b/packages/desktop-client/src/components/mobile/MobileForms.test.tsx
@@ -0,0 +1,75 @@
+import { render, screen } from '@testing-library/react';
+import userEvent from '@testing-library/user-event';
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+
+import { InputField } from './MobileForms';
+
+describe('InputField', () => {
+ const showPicker = vi.fn();
+
+ beforeEach(() => {
+ // jsdom does not implement showPicker
+ HTMLInputElement.prototype.showPicker = showPicker;
+ });
+
+ afterEach(() => {
+ showPicker.mockReset();
+ Reflect.deleteProperty(HTMLInputElement.prototype, 'showPicker');
+ });
+
+ it('opens the native picker when a date field with an icon is clicked', async () => {
+ render(
+ <InputField
+ type="date"
+ iconStart={<span />}
+ defaultValue="2026-02-10"
+ data-testid="field"
+ />,
+ );
+
+ await userEvent.click(screen.getByTestId('field'));
+
+ expect(showPicker).toHaveBeenCalledTimes(1);
+ });
+
+ it('opens the native picker when a month field without an icon is clicked', async () => {
+ render(
+ <InputField type="month" defaultValue="2026-02" data-testid="field" />,
+ );
+
+ await userEvent.click(screen.getByTestId('field'));
+
+ expect(showPicker).toHaveBeenCalledTimes(1);
+ });
+
+ it('does not open a picker for a text field', async () => {
+ render(<InputField data-testid="field" />);
+
+ await userEvent.click(screen.getByTestId('field'));
+
+ expect(showPicker).not.toHaveBeenCalled();
+ });
+
+ it('still calls the provided onClick', async () => {
+ const onClick = vi.fn();
+ render(<InputField type="date" onClick={onClick} data-testid="field" />);
+
+ await userEvent.click(screen.getByTestId('field'));
+
+ expect(onClick).toHaveBeenCalledTimes(1);
+ expect(showPicker).toHaveBeenCalledTimes(1);
+ });
+
+ it('ignores a browser that refuses to open the picker', async () => {
+ showPicker.mockImplementation(() => {
+ throw new DOMException('not allowed', 'NotAllowedError');
+ });
+ const onClick = vi.fn();
+ render(<InputField type="date" onClick={onClick} data-testid="field" />);
+
+ await userEvent.click(screen.getByTestId('field'));
+
+ expect(showPicker).toHaveBeenCalledTimes(1);
+ expect(onClick).toHaveBeenCalledTimes(1);
+ });
+});
diff --git a/packages/desktop-client/src/components/mobile/MobileForms.tsx b/packages/desktop-client/src/components/mobile/MobileForms.tsx
index 4f82bbde9f..8d5a1c63dd 100644
--- a/packages/desktop-client/src/components/mobile/MobileForms.tsx
+++ b/packages/desktop-client/src/components/mobile/MobileForms.tsx
@@ -56,6 +56,24 @@ export const hideNativeDateIconClassName = css({
},
});
+const nativePickerInputTypes = new Set([
+ 'date',
+ 'month',
+ 'time',
+ 'week',
+ 'datetime-local',
+]);
+
+// browsers don't reliably open the native picker when the field itself is
+// tapped (chromium only opens it from the indicator, which can be hidden)
+function showNativePicker(input: HTMLInputElement) {
+ try {
+ input.showPicker();
+ } catch {
+ // unsupported or blocked; the browser's default tap behavior still applies
+ }
+}
+
const iconFieldWrapperClassName = css({
...valueStyle,
flexDirection: 'row',
@@ -89,9 +107,18 @@ export function InputField({
iconStart,
iconEnd,
className,
+ type,
+ onClick,
ref,
...props
}: InputFieldProps) {
+ const onClickInner: InputFieldProps['onClick'] = event => {
+ onClick?.(event);
+ if (type && nativePickerInputTypes.has(type) && !event.defaultPrevented) {
+ showNativePicker(event.currentTarget);
+ }
+ };
+
if (iconStart || iconEnd) {
return (
<View
@@ -105,10 +132,12 @@ export function InputField({
{iconStart && <View style={iconStyle}>{iconStart}</View>}
<Input
ref={ref}
+ type={type}
autoCorrect="false"
autoCapitalize="none"
disabled={disabled}
onUpdate={onUpdate}
+ onClick={onClickInner}
style={{
flex: 1,
border: 'none',
@@ -139,10 +168,12 @@ export function InputField({
return (
<Input
ref={ref}
+ type={type}
autoCorrect="false"
autoCapitalize="none"
disabled={disabled}
onUpdate={onUpdate}
+ onClick={onClickInner}
className={className}
style={{
...valueStyle,
diff --git a/upcoming-release-notes/fix-mobile-date-picker-chrome.md b/upcoming-release-notes/fix-mobile-date-picker-chrome.md
new file mode 100644
index 0000000000..fa655fbc59
--- /dev/null
+++ b/upcoming-release-notes/fix-mobile-date-picker-chrome.md
@@ -0,0 +1,6 @@
+---
+category: Bugfixes
+authors: [MikesGlitch]
+---
+
+Fix the date picker not opening on mobile in recent versions of Chrome