nmrium icon indicating copy to clipboard operation
nmrium copied to clipboard

Issue with space event bubbling

Open lpatiny opened this issue 2 months ago • 7 comments

@targos We need your advice on how to solve this issue.

Currently we can toggle to show / hide custom atom labels. If the last thing we did is to click on such a toggle the element is 'focussed'.

Now if we go hover an atom and press 'space' the event will number the atom but also invert the toggle button. How should we prevent the bubbling of the event so that it does not leave the molecule ?

Image

lpatiny avatar Nov 11 '25 08:11 lpatiny

You're asking the wrong person. @tpoisseau implemented this interaction.

targos avatar Nov 11 '25 08:11 targos

But I think you're also asking the wrong question. You have the focus on the button, so it's where the event happens. Bubbling is what makes your interaction work on the molecule. If we stop bubbling, you would have the toggle on the button and nothing else.

targos avatar Nov 11 '25 08:11 targos

This happens because the focus is currently on another element, which is the expected behavior when the space key is pressed.

hamed-musallam avatar Nov 11 '25 09:11 hamed-musallam

I am actually surprised that the labeling works without having specifically taken the focus on the molecule. If that's really wanted, you need to listen to the event in "capture" mode and stop the propagation of the event there (in react-ocl).

targos avatar Nov 11 '25 09:11 targos

Related (I think) and not easy to predict as a user: if you have the focus on a text field, pressing keyboard keys over a molecule may or may not write in the field depending on the key:

https://github.com/user-attachments/assets/c508e085-89ba-4d74-a0fa-9b8a03807621

targos avatar Nov 11 '25 09:11 targos

One possible workaround solution is to automatically focus the atom element when the mouse hovers over it. As you can see in react-ocl it listens to a global key listener

https://github.com/zakodium-oss/react-ocl/blob/123ff7f7ead59a7b231e5ab301fefcfd6bf733d1/src/components/svg/svg_editor.tsx#L82-L108

https://github.com/zakodium-oss/react-ocl/blob/123ff7f7ead59a7b231e5ab301fefcfd6bf733d1/src/components/svg/svg_editor.tsx#L117-L122

hamed-musallam avatar Nov 11 '25 11:11 hamed-musallam

About the issue, on react-ocl the listeners are global because there is no focusable element in the svg.

Maybe the best things to do, is (in react-ocl) to skip the event if target is a focusable element or an element outside the the svg editor.

tpoisseau avatar Nov 12 '25 08:11 tpoisseau