Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Datatable: CellEdit and general issues with portal editors #7405

Open
gnawjaren opened this issue Nov 10, 2024 · 0 comments
Open

Datatable: CellEdit and general issues with portal editors #7405

gnawjaren opened this issue Nov 10, 2024 · 0 comments
Labels
Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible

Comments

@gnawjaren
Copy link
Contributor

Describe the bug

There are a few issues with portal editors like dropdown and alike - caused by the onClickOutside and closing edit mode.
There were a few changes that adressed this, but some issues remain - like not being able to filter in dropdown and some other issues in other editors. I can give a repro, but i think the issue is well known.
For us it is critical to have such options, like dropdown filter.
#7158 #2666 #5320
#3079 #2097

I have tested a different approach to solve this:

diff --git a/components/lib/datatable/BodyCell.js b/components/lib/datatable/BodyCell.js
index 043d2160a..701156235 100644
--- a/components/lib/datatable/BodyCell.js
+++ b/components/lib/datatable/BodyCell.js
@@ -63,9 +63,17 @@ export const BodyCell = React.memo((props) => {
         return getColumnProp('cellEditValidateOnClose');
     };

+    const isIgnoredElement = (element) => {
+        const isCellEditor = (el) => el.getAttribute && el.getAttribute('data-p-is-cell-editor');
+        return isCellEditor(element) || DomHandler.getParents(element).find((el) => isCellEditor(el));
+    };
+
     const [bindDocumentClickListener, unbindDocumentClickListener] = useEventListener({
         type: 'click',
         listener: (e) => {
+            if (isIgnoredElement(e.target)) {
+                return
+            }
             setTimeout(() => {
                 if (!selfClick.current && isOutsideClicked(e.target)) {
                     // #2666 for overlay components and outside is clicked

This does give the option to control if you wish to ignore the overlay on outside click, i tested this local and it works fine - with primereact components and even third party. It gives you the option to add this attribute to the overlay (e.g.

pt={
  panel:{
    "data-p-is-cell-editor":true
  }
}

or just create an element on the root page, append the cell editors there and call it a day.
I just wrote and tested this as a proof of concept, maybe there are better ways - but i think the approach to provide an option to ignore specific editors would be great for many use cases. And it doesnt break anything.
I can provide a pr if this approach seems ok.
Kind regards and have a good day!

Reproducer

No response

System Information

primereact: 10.8.4
react: 18.3.1

Steps to reproduce the behavior

Use an editor with portal in Datatable with editmode="cell" and try to interact with it.

Expected behavior

Interaction with the component - not closing of the editor on click.

@gnawjaren gnawjaren added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Nov 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible
Projects
None yet
Development

No branches or pull requests

1 participant