@arquimedes.co/eureka-forms 3.0.67 → 3.0.68
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Shared/ErkDatePicker/ErkDatePicker.js +10 -4
- package/dist/Shared/ErkDatePicker/ErkDatePicker.locale.test.d.ts +1 -0
- package/dist/Shared/ErkDatePicker/ErkDatePicker.locale.test.js +39 -0
- package/dist/Shared/ErkDateRangePicker/ErkDateRangePicker.js +14 -10
- package/dist/Shared/ErkSelect/ErkSelect.js +9 -1
- package/dist/Shared/ErkSelect/ErkSelect.test.d.ts +2 -0
- package/dist/Shared/ErkSelect/ErkSelect.test.js +53 -0
- package/dist/Shared/ErkTimePicker/ErkTimePicker.js +8 -1
- package/dist/Shared/ErkTimePicker/ErkTimePicker.test.d.ts +2 -0
- package/dist/Shared/ErkTimePicker/ErkTimePicker.test.js +24 -0
- package/dist/Utils/LocaleUtils.d.ts +1 -0
- package/dist/Utils/LocaleUtils.js +10 -3
- package/package.json +1 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import React, { useMemo } from 'react';
|
|
3
|
-
import {
|
|
3
|
+
import { isValid } from 'date-fns';
|
|
4
4
|
import { InputAdornment, styled, Dialog as MuiDialog } from '@mui/material';
|
|
5
|
-
import { MobileDatePicker as MuiDatePicker, MobileDateTimePicker as MuiDateTimePicker, DatePickerToolbar as MuiDatePickerToolbar, DateTimePickerToolbar as MuiDateTimePickerToolbar, usePickerContext, PickerDay as MuiPickerDay, renderTimeViewClock, } from '@mui/x-date-pickers';
|
|
5
|
+
import { MobileDatePicker as MuiDatePicker, MobileDateTimePicker as MuiDateTimePicker, DatePickerToolbar as MuiDatePickerToolbar, DateTimePickerToolbar as MuiDateTimePickerToolbar, usePickerContext, usePickerAdapter, PickerDay as MuiPickerDay, renderTimeViewClock, } from '@mui/x-date-pickers';
|
|
6
6
|
import { StyledTextField } from '../ErkTextField/ErkTextField';
|
|
7
7
|
import CalendarIcon from '../../Icons/CalendarIcon';
|
|
8
8
|
const StyledDateTimePicker = styled(MuiDateTimePicker, {
|
|
@@ -138,18 +138,24 @@ const StyledDay = styled(MuiPickerDay)(({ theme }) => ({
|
|
|
138
138
|
}));
|
|
139
139
|
function CustomPickerField({ error, required, helperText, size = 'small', labelMargin = 5, inputRef, fullWidth = true, }) {
|
|
140
140
|
const { value, fieldFormat, setOpen, disabled, readOnly, label } = usePickerContext();
|
|
141
|
+
// Format through the adapter so the LocalizationProvider locale applies (a bare date-fns
|
|
142
|
+
// `format` always used en-US, so Spanish users saw MM/dd/yyyy).
|
|
143
|
+
const adapter = usePickerAdapter();
|
|
141
144
|
const { displayValue, isInvalid } = useMemo(() => {
|
|
142
145
|
if (!value)
|
|
143
146
|
return { displayValue: '', isInvalid: false };
|
|
144
147
|
if (!isValid(value))
|
|
145
148
|
return { displayValue: '', isInvalid: true };
|
|
146
149
|
try {
|
|
147
|
-
return {
|
|
150
|
+
return {
|
|
151
|
+
displayValue: adapter.formatByString(value, fieldFormat ?? adapter.formats.keyboardDate),
|
|
152
|
+
isInvalid: false,
|
|
153
|
+
};
|
|
148
154
|
}
|
|
149
155
|
catch {
|
|
150
156
|
return { displayValue: '', isInvalid: true };
|
|
151
157
|
}
|
|
152
|
-
}, [value, fieldFormat]);
|
|
158
|
+
}, [value, fieldFormat, adapter]);
|
|
153
159
|
const handleClick = () => {
|
|
154
160
|
if (!disabled && !readOnly) {
|
|
155
161
|
setOpen((prev) => !prev);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import '@testing-library/jest-dom';
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { render } from '@testing-library/react';
|
|
3
|
+
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
4
|
+
import '@testing-library/jest-dom';
|
|
5
|
+
import MaterialProviders from '../../Utils/MaterialProviders';
|
|
6
|
+
import InternalFormStyle from '../../constants/InternalFormStyle';
|
|
7
|
+
import ErkDatePicker from './ErkDatePicker';
|
|
8
|
+
import ErkDateRangePicker from '../ErkDateRangePicker/ErkDateRangePicker';
|
|
9
|
+
/**
|
|
10
|
+
* The field text used to be built with a bare date-fns `format`, which ignores the
|
|
11
|
+
* LocalizationProvider locale and always printed en-US dates (MM/dd/yyyy).
|
|
12
|
+
*/
|
|
13
|
+
const setLanguages = (languages) => {
|
|
14
|
+
vi.spyOn(navigator, 'languages', 'get').mockReturnValue(languages);
|
|
15
|
+
};
|
|
16
|
+
const date = new Date(2026, 2, 9, 14, 5); // 9 de marzo de 2026, 14:05
|
|
17
|
+
describe('date pickers follow the browser locale', () => {
|
|
18
|
+
afterEach(() => vi.restoreAllMocks());
|
|
19
|
+
it('shows dd/MM/yyyy for a Spanish browser', () => {
|
|
20
|
+
setLanguages(['es-CO', 'es']);
|
|
21
|
+
render(_jsx(MaterialProviders, { formStyle: InternalFormStyle, children: _jsx(ErkDatePicker, { label: "Fecha", value: date, onChange: vi.fn() }) }));
|
|
22
|
+
expect(document.querySelector('input')?.value).toBe('09/03/2026');
|
|
23
|
+
});
|
|
24
|
+
it('shows MM/dd/yyyy for a US browser', () => {
|
|
25
|
+
setLanguages(['en-US', 'en']);
|
|
26
|
+
render(_jsx(MaterialProviders, { formStyle: InternalFormStyle, children: _jsx(ErkDatePicker, { label: "Fecha", value: date, onChange: vi.fn() }) }));
|
|
27
|
+
expect(document.querySelector('input')?.value).toBe('03/09/2026');
|
|
28
|
+
});
|
|
29
|
+
it('shows a localized date-time for a Spanish browser', () => {
|
|
30
|
+
setLanguages(['es']);
|
|
31
|
+
render(_jsx(MaterialProviders, { formStyle: InternalFormStyle, children: _jsx(ErkDatePicker, { pickTime: true, label: "Fecha y hora", value: date, onChange: vi.fn() }) }));
|
|
32
|
+
expect(document.querySelector('input')?.value).toMatch(/^09\/03\/2026 02:05 (p\. ?m\.|PM)$/i);
|
|
33
|
+
});
|
|
34
|
+
it('shows a dd/MM/yyyy range for a Spanish browser', () => {
|
|
35
|
+
setLanguages(['es-MX']);
|
|
36
|
+
render(_jsx(MaterialProviders, { formStyle: InternalFormStyle, children: _jsx(ErkDateRangePicker, { label: "Rango", value: [date, new Date(2026, 2, 20)], onChange: vi.fn() }) }));
|
|
37
|
+
expect(document.querySelector('input')?.value).toBe('09/03/2026 – 20/03/2026');
|
|
38
|
+
});
|
|
39
|
+
});
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import React, { useMemo } from 'react';
|
|
3
3
|
import { InputAdornment, styled, Dialog as MuiDialog } from '@mui/material';
|
|
4
|
-
import { DatePickerToolbar as MuiDatePickerToolbar, usePickerContext, } from '@mui/x-date-pickers';
|
|
4
|
+
import { DatePickerToolbar as MuiDatePickerToolbar, usePickerContext, usePickerAdapter, } from '@mui/x-date-pickers';
|
|
5
5
|
import { MobileDateRangePicker as MuiDateRangePicker, DateRangePickerDay as MuiDateRangePickerDay, } from '@mui/x-date-pickers-pro';
|
|
6
|
-
import {
|
|
6
|
+
import { isValid } from 'date-fns';
|
|
7
7
|
import { StyledTextField } from '../ErkTextField/ErkTextField';
|
|
8
8
|
import CalendarIcon from '../../Icons/CalendarIcon';
|
|
9
9
|
const StyledDateRangePicker = styled(MuiDateRangePicker, {
|
|
@@ -85,6 +85,9 @@ const StyledDay = styled(MuiDateRangePickerDay)(({ theme }) => ({
|
|
|
85
85
|
}));
|
|
86
86
|
const CustomRangePickerField = React.forwardRef(function CustomRangePickerField({ error, required, helperText, size = 'small', labelMargin = 5, fullWidth = true, inputRef }, ref) {
|
|
87
87
|
const { value, fieldFormat, setOpen, disabled, readOnly, label } = usePickerContext();
|
|
88
|
+
// Format through the adapter so the LocalizationProvider locale applies (a bare date-fns
|
|
89
|
+
// `format` always used en-US, so Spanish users saw MM/dd/yyyy).
|
|
90
|
+
const adapter = usePickerAdapter();
|
|
88
91
|
const { displayValue, isInvalid } = useMemo(() => {
|
|
89
92
|
const [startDate, endDate] = value ?? [null, null];
|
|
90
93
|
if (!startDate)
|
|
@@ -94,15 +97,15 @@ const CustomRangePickerField = React.forwardRef(function CustomRangePickerField(
|
|
|
94
97
|
if (endDate && !isValid(endDate))
|
|
95
98
|
return { displayValue: '', isInvalid: true };
|
|
96
99
|
try {
|
|
97
|
-
const fmt = fieldFormat ??
|
|
98
|
-
const start =
|
|
99
|
-
const end = endDate ?
|
|
100
|
+
const fmt = fieldFormat ?? adapter.formats.keyboardDate;
|
|
101
|
+
const start = adapter.formatByString(startDate, fmt);
|
|
102
|
+
const end = endDate ? adapter.formatByString(endDate, fmt) : '';
|
|
100
103
|
return { displayValue: end ? `${start} – ${end}` : start, isInvalid: false };
|
|
101
104
|
}
|
|
102
105
|
catch {
|
|
103
106
|
return { displayValue: '', isInvalid: true };
|
|
104
107
|
}
|
|
105
|
-
}, [value, fieldFormat]);
|
|
108
|
+
}, [value, fieldFormat, adapter]);
|
|
106
109
|
const handleClick = () => {
|
|
107
110
|
if (!disabled && !readOnly) {
|
|
108
111
|
setOpen((prev) => !prev);
|
|
@@ -118,10 +121,10 @@ const CustomRangePickerField = React.forwardRef(function CustomRangePickerField(
|
|
|
118
121
|
},
|
|
119
122
|
} }));
|
|
120
123
|
});
|
|
121
|
-
const formatDate = (date, showYear) => {
|
|
124
|
+
const formatDate = (adapter, date, showYear) => {
|
|
122
125
|
if (!date || !isValid(date))
|
|
123
126
|
return '';
|
|
124
|
-
return
|
|
127
|
+
return adapter.formatByString(date, showYear ? adapter.formats.fullDate : 'dd MMM');
|
|
125
128
|
};
|
|
126
129
|
function CustomDatePickerRange({ error, disabled, readOnly, helperText, size = 'small', labelMargin = 5, value, onChange, inputRef, shortcuts, label, required, ...others }) {
|
|
127
130
|
// MUI X v9 no longer forwards `required` to the field-slot label when the field is a Material
|
|
@@ -129,6 +132,7 @@ function CustomDatePickerRange({ error, disabled, readOnly, helperText, size = '
|
|
|
129
132
|
// The picker's `label` does propagate to the field via the picker context, so bake the marker
|
|
130
133
|
// into the label to keep the required indicator visible.
|
|
131
134
|
const displayLabel = required && typeof label === 'string' ? `${label} *` : label;
|
|
135
|
+
const adapter = usePickerAdapter();
|
|
132
136
|
const [startDate, endDate] = value ?? [null, null];
|
|
133
137
|
const hasCompleteRange = Boolean(startDate) && Boolean(endDate);
|
|
134
138
|
const showYear = startDate &&
|
|
@@ -136,8 +140,8 @@ function CustomDatePickerRange({ error, disabled, readOnly, helperText, size = '
|
|
|
136
140
|
isValid(startDate) &&
|
|
137
141
|
isValid(endDate) &&
|
|
138
142
|
startDate.getFullYear() !== endDate.getFullYear();
|
|
139
|
-
const formattedStartDate = formatDate(startDate, Boolean(showYear));
|
|
140
|
-
const formattedEndDate = formatDate(endDate, Boolean(showYear));
|
|
143
|
+
const formattedStartDate = formatDate(adapter, startDate, Boolean(showYear));
|
|
144
|
+
const formattedEndDate = formatDate(adapter, endDate, Boolean(showYear));
|
|
141
145
|
const toolbarText = hasCompleteRange ? `${formattedStartDate} – ${formattedEndDate}` : '– –';
|
|
142
146
|
return (_jsx(StyledDateRangePicker, { ...others, label: displayLabel, value: value, onChange: onChange, size: size, disabled: disabled, readOnly: readOnly, reduceAnimations: true, showDaysOutsideCurrentMonth: true, slots: {
|
|
143
147
|
field: CustomRangePickerField,
|
|
@@ -109,7 +109,15 @@ function CustomSelect({ label, error, value, loading, onChange, children, requir
|
|
|
109
109
|
setOpen((open) => !open);
|
|
110
110
|
}
|
|
111
111
|
}, children: _jsx(IconComponent, { size: size === 'small' ? 22 : 26 }) })) : undefined, onFocus: (e) => {
|
|
112
|
-
|
|
112
|
+
// Open only when focus arrives by keyboard from another control. A focus with no
|
|
113
|
+
// relatedTarget is either a mouse press (MUI's own mousedown already opens the menu)
|
|
114
|
+
// or the focus trap handing focus back after the menu closed; opening on that one
|
|
115
|
+
// reopened the menu right after a backdrop click and kept it stuck open.
|
|
116
|
+
const from = e.relatedTarget;
|
|
117
|
+
const cameFromAnotherControl = from !== null &&
|
|
118
|
+
from.closest('.Erk-MuiPaper-root') === null &&
|
|
119
|
+
!e.currentTarget.parentElement?.contains(from);
|
|
120
|
+
if (cameFromAnotherControl) {
|
|
113
121
|
setOpen(true);
|
|
114
122
|
}
|
|
115
123
|
others.onFocus?.(e);
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { render, screen, fireEvent, act } from '@testing-library/react';
|
|
3
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
4
|
+
import '@testing-library/jest-dom';
|
|
5
|
+
import '../../Utils/MuiClassnameSetup';
|
|
6
|
+
import MaterialProviders from '../../Utils/MaterialProviders';
|
|
7
|
+
import InternalFormStyle from '../../constants/InternalFormStyle';
|
|
8
|
+
import ErkSelect from './ErkSelect';
|
|
9
|
+
import ErkMenuItem from '../ErkMenuItem';
|
|
10
|
+
function renderSelect() {
|
|
11
|
+
render(_jsxs(MaterialProviders, { formStyle: InternalFormStyle, children: [_jsx("input", { "data-testid": "before" }), _jsxs(ErkSelect, { label: "Opci\u00F3n", onChange: vi.fn(), children: [_jsx(ErkMenuItem, { value: "a", children: "A" }), _jsx(ErkMenuItem, { value: "b", children: "B" })] })] }));
|
|
12
|
+
}
|
|
13
|
+
// The inline (disablePortal) menu marks the rest of the tree aria-hidden while open, so the
|
|
14
|
+
// combobox is read from the raw DOM; the paper also stays mounted through its exit transition,
|
|
15
|
+
// so the open state comes from aria-expanded rather than from the listbox being present.
|
|
16
|
+
const combobox = () => document.querySelector('[role=combobox]');
|
|
17
|
+
const isOpen = () => combobox().getAttribute('aria-expanded') === 'true';
|
|
18
|
+
const openSelect = () => {
|
|
19
|
+
fireEvent.mouseDown(combobox());
|
|
20
|
+
};
|
|
21
|
+
const flush = () => act(() => new Promise((resolve) => setTimeout(resolve, 50)));
|
|
22
|
+
describe('ErkSelect open/close', () => {
|
|
23
|
+
it('opens on mouse down', () => {
|
|
24
|
+
renderSelect();
|
|
25
|
+
openSelect();
|
|
26
|
+
expect(isOpen()).toBe(true);
|
|
27
|
+
});
|
|
28
|
+
it('stays closed after clicking the backdrop (does not reopen on focus restore)', async () => {
|
|
29
|
+
renderSelect();
|
|
30
|
+
openSelect();
|
|
31
|
+
const backdrop = document.querySelector('.Erk-MuiBackdrop-root');
|
|
32
|
+
fireEvent.click(backdrop);
|
|
33
|
+
await flush();
|
|
34
|
+
// The focus trap gives focus back to the combobox with no relatedTarget (the mouse left focus on body).
|
|
35
|
+
fireEvent.focus(combobox(), { relatedTarget: null });
|
|
36
|
+
await flush();
|
|
37
|
+
expect(isOpen()).toBe(false);
|
|
38
|
+
});
|
|
39
|
+
it('stays closed after picking an option', async () => {
|
|
40
|
+
renderSelect();
|
|
41
|
+
openSelect();
|
|
42
|
+
fireEvent.click(document.querySelector('[role=option][data-value=b]'));
|
|
43
|
+
await flush();
|
|
44
|
+
expect(isOpen()).toBe(false);
|
|
45
|
+
});
|
|
46
|
+
it('opens when reached by keyboard from another field', () => {
|
|
47
|
+
renderSelect();
|
|
48
|
+
const before = screen.getByTestId('before');
|
|
49
|
+
before.focus();
|
|
50
|
+
fireEvent.focus(combobox(), { relatedTarget: before });
|
|
51
|
+
expect(isOpen()).toBe(true);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
@@ -62,7 +62,14 @@ function CustomSelect({ value, onChange, label, error, required, pickDays, helpe
|
|
|
62
62
|
if (!readOnly && !disabled)
|
|
63
63
|
setOpen(!open);
|
|
64
64
|
}, children: _jsx(ClockIcon, { size: size === 'small' ? 22 : 26 }) }), onFocus: (e) => {
|
|
65
|
-
|
|
65
|
+
// Same rule as ErkSelect: open only when focus arrives from another control. A focus
|
|
66
|
+
// with no relatedTarget is the hidden menu handing focus back on close, and opening on
|
|
67
|
+
// it reopened the popper right after every click away.
|
|
68
|
+
const from = e.relatedTarget;
|
|
69
|
+
const cameFromAnotherControl = from !== null &&
|
|
70
|
+
from.closest('.Erk-MuiPaper-root') === null &&
|
|
71
|
+
!e.currentTarget.parentElement?.contains(from);
|
|
72
|
+
if (cameFromAnotherControl && !readOnly && !disabled) {
|
|
66
73
|
setOpen(true);
|
|
67
74
|
}
|
|
68
75
|
}, onOpen: () => {
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { render, fireEvent, act } from '@testing-library/react';
|
|
3
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
4
|
+
import '@testing-library/jest-dom';
|
|
5
|
+
import '../../Utils/MuiClassnameSetup';
|
|
6
|
+
import MaterialProviders from '../../Utils/MaterialProviders';
|
|
7
|
+
import InternalFormStyle from '../../constants/InternalFormStyle';
|
|
8
|
+
import ErkTimePicker from './ErkTimePicker';
|
|
9
|
+
const combobox = () => document.querySelector('[role=combobox]');
|
|
10
|
+
const isOpen = () => combobox().getAttribute('aria-expanded') === 'true';
|
|
11
|
+
const flush = () => act(() => new Promise((resolve) => setTimeout(resolve, 50)));
|
|
12
|
+
describe('ErkTimePicker open/close', () => {
|
|
13
|
+
it('closes on click away and stays closed when focus returns to the trigger', async () => {
|
|
14
|
+
render(_jsxs(MaterialProviders, { formStyle: InternalFormStyle, children: [_jsx("button", { "data-testid": "outside", children: "fuera" }), _jsx(ErkTimePicker, { label: "Tiempo", pickHours: true, pickMinutes: true, onChange: vi.fn() })] }));
|
|
15
|
+
fireEvent.mouseDown(combobox());
|
|
16
|
+
await flush();
|
|
17
|
+
expect(isOpen()).toBe(true);
|
|
18
|
+
fireEvent.mouseDown(document.querySelector('[data-testid=outside]'));
|
|
19
|
+
await flush();
|
|
20
|
+
fireEvent.focus(combobox(), { relatedTarget: null });
|
|
21
|
+
await flush();
|
|
22
|
+
expect(isOpen()).toBe(false);
|
|
23
|
+
});
|
|
24
|
+
});
|
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
import { enUS } from 'date-fns/locale/en-US';
|
|
2
|
+
import { enGB } from 'date-fns/locale/en-GB';
|
|
2
3
|
import { es } from 'date-fns/locale/es';
|
|
3
4
|
const localeMap = {
|
|
4
5
|
en: enUS,
|
|
5
6
|
'en-US': enUS,
|
|
7
|
+
'en-GB': enGB,
|
|
6
8
|
es,
|
|
7
9
|
};
|
|
10
|
+
const browserLanguage = () => navigator.languages?.length
|
|
11
|
+
? navigator.languages[0]
|
|
12
|
+
: (navigator.userLanguage ?? navigator.language ?? navigator.browserLanguage);
|
|
13
|
+
/** date-fns locale for the browser language: exact tag first, then its base language (es-CO → es), else Spanish. */
|
|
8
14
|
export const getLocale = () => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
15
|
+
const language = browserLanguage();
|
|
16
|
+
if (!language)
|
|
17
|
+
return es;
|
|
18
|
+
return localeMap[language] ?? localeMap[language.split('-')[0]] ?? es;
|
|
12
19
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arquimedes.co/eureka-forms",
|
|
3
3
|
"repository": "git://github.com/Arquimede5/Eureka-Forms.git",
|
|
4
|
-
"version": "3.0.
|
|
4
|
+
"version": "3.0.68",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"watch": "node node_modules/@typescript/native/bin/tsc --noEmit --watch --project tsconfig.app.json",
|
|
7
7
|
"start": "vite",
|