ReactJS MUI Select Component: Get pre-select value - reactjs

Is there a native MUI event for when the pre-selection value changes in a MUI:Select component?
For example, here is my MUI:Select component with 3 options:
I would like an event for when 'Public', 'Restricted' or 'Private' is pre-selected (but not actually selected; i.e. before the onChange() event), either with a mouse-over event or a keyboard up/down event. This is because I have a tooltip card that needs to change dynamically for the user as they interact with the options.
Using this example https://codesandbox.io/s/3iv96 as a guide, I implemented a bespoke solution by capturing the mouse-over event and extracting the text value. I just realized I have forgotten to handle key up/down.
So the question becomes whether I have just missed the obvious, or do I need to roll my own component by wrapping MUI:Select and publishing the events I need.

Looks like out of the box this isn't supported.
Looking at this thread https://github.com/JedWatson/react-select/issues/745 it has to be done manually.

Related

Ag-Grid keep custom filter open during interaction with dropdown

I have a custom filter component I'm giving Ag grid for each column. The component contains a dropdown. When user selects an option from dropdown, the filter closes immediately on selection rather than staying open like it should.
How can I keep the filter component to stay open on selection of option from dropdown?
Reading the docs more, I found the answer here:
https://www.ag-grid.com/javascript-data-grid/component-filter/#custom-filters-containing-a-popup-element
Custom Filters Containing a Popup Element
Sometimes you will need to create custom components for your filters that also contain popup elements. This is the case for Date Filter as it pops up a Date Picker. If the library you use anchors the popup element outside of the parent filter, then when you click on it the grid will think you clicked outside of the filter and hence close the column menu.
There are two ways you can get fix this problem:
Add a mouse click listener to your floating element and set it to
preventDefault(). This way, the click event will not bubble up to the
grid. This is the best solution, but you can only do this if you are
writing the component yourself.
Add the ag-custom-component-popup CSS
class to your floating element. An example of this usage can be found
here: Custom Date Component

Handling focus with react-select

I'm trying to figure out how to work around what appears to be greedy-focus issues with react-select.
I'm using custom components in my MenuList component that need the focus to work (rc-slider). Basically, I'd like the select to support an additional value for each option and I'm using a Slider to do that.
The issue with the sliders is that I can click on them to change the value, but can't drag the handles, as the Select seems to take back the focus (and even close the drop-down if menuIsOpen is not controlled).
The select does need to re-render when the values change, but I can't figure out why the focus has to change.
https://codesandbox.io/s/epic-moon-cv33b

FocusListener on Tabs/ScaleImageLabel

I've added ScaleImageLabel to swipe Tabs. I want to calculate amount of time each tab remains in focus. I added focus listener to Tabs/ScaleImageLabel but it's not getting fired. It's working when added to the form. Any suggestions on how to achieve it?
If I understand correctly what you need is a tab selection listener. Focus listener will only work for focusable components and labels are by default non-focusable. I would recommend avoiding it since focus is used for key based navigation. It might produce different results than you would expect.

Can't select text within draggable

I find that when a div containing text is draggable I can't select the text.
If I remove the DnD stuff then I can select the text.
Is there a way of having both?
A key wrinkle in the question seems to be which precise UX design to support.
A state toggle is one way to resolve that issue. Place a checkbox or other toggle control somewhere, either per-item or global. When toggled with drag off and select on, (let's call this the "off" state), then user could select. When toggled drag on and select off (let's call this the "on" state), then user could drag. You could leverage React to enable DnD behavior only in the latter case of "on" state (like even literally don't include the drag-and-drop wrappers when "off").
Another option is some other gesture recognition like long-click/tap, which react-dnd may not support. You've mentioned some other possibilities like double-click and making the text itself not draggable.

How do I determine component with focus in a codenameone container?

I am building a json editor in codenameone. In my current design I need to insert or remove components that have focus when a menu command is pressed. So for instance if i have TextFields inside a Container , I need to determine which textfield has focus when I press the insert menu option so that I can insert another component there.
On the current form (you can get the current form using Display.getInstance().getCurrent()) invoke getFocused(). You can also bind a focus listener using addFocusListener on the form or on the component you want to track.
Notice that with touch device the concept of focus isn't quite the same since focus isn't marked on such devices.

Resources