primefaces / primereact

The Most Complete React UI Component Library
https://primereact.org
MIT License
6.96k stars 1.06k forks source link

fix(BodyCell): prevent cell or row refocus when overlay clicked #7401

Closed KumJungMin closed 2 weeks ago

KumJungMin commented 2 weeks ago

Defect Fixes


How To Resolve

Issue 1, Calendar Overlay Position Issue

Issue 2, Calendar Overlay Cannot Select the Day Label Issue

React.useEffect(() => {
    if (getColumnProp('frozen')) {
        updateStickyPosition();
    }
    if (props.editMode === 'cell' || props.editMode === 'row') {
        focusOnElement();
    }
}, [props.editMode, props.editing, editingState]); // Updated to include dependencies

Issue 3, Focus Remains When Clicking Outside of the Cell


Test

sample code ```js import { Calendar } from '@/components/lib/calendar/Calendar'; import { DataTable } from '@/components/lib/datatable/DataTable'; import { Column } from '@/components/lib/column/Column'; import { useState, useCallback } from 'react'; export function BasicDoc() { return ( <> ); } const Test = () => { const [data, setData] = useState([ { id: 1, date: null }, { id: 2, date: '2024-01-01T00:00:00.000Z' }, { id: 3, date: '2024-02-02T00:00:00.000Z' } ]); const formatDate = (date) => { return date ? new Date(date).toLocaleDateString('es-ES') : ''; }; const dateEditor = useCallback( (options, col) => { const value = options.value; const isValidDate = value && !isNaN(Date.parse(value)); const dateValue = isValidDate ? new Date(value) : null; if (dateValue) { dateValue.setHours(12); } return ( { const selectedDate = e.value; if (selectedDate) selectedDate.setHours(12); const newData = [...data]; const index = options.rowIndex; newData[index] = { ...newData[index], date: selectedDate }; setData(newData); // console.log('newData', newData); // console.log(selectedDate); // console.log(options); options.editorCallback(selectedDate); // console.log(options); }} mask="99/99/9999" dateFormat="dd/mm/yy" showButtonBar showIcon /> ); }, [data] ); return (

TABLE

formatDate(rowData.date)} // Usar formatDate para mostrar la fecha editor={(options) => dateEditor(options, 'date')} dataType="date" />
); }; ```

Before

https://github.com/user-attachments/assets/ab53197a-24c8-4ad1-ac1c-32e40ea487e1

After

https://github.com/user-attachments/assets/0323d7e8-42ef-46ef-b90a-9c8d6e593616

vercel[bot] commented 2 weeks ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

2 Skipped Deployments | Name | Status | Preview | Updated (UTC) | | :--- | :----- | :------ | :------ | | **primereact** | ⬜️ Ignored ([Inspect](https://vercel.com/primetek/primereact/G3UJ2JwN4wHNpJ2PviyAcuKHjeLV)) | [Visit Preview](https://primereact-git-fork-kumjungmin-fix-issue-7389-primetek.vercel.app) | Nov 8, 2024 0:08am | | **primereact-v9** | ⬜️ Ignored ([Inspect](https://vercel.com/primetek/primereact-v9/CFHkZ7jMPMYKm7K1CcckZaknKYDh)) | [Visit Preview](https://primereact-v9-git-fork-kumjungmin-fix-issue-7389-primetek.vercel.app) | Nov 8, 2024 0:08am |