React Material UI DropDown testing - reactjs

How should the second parameter of the React TestUtils.Simulate.change.(MyDropdown, ???) look like to trigger a change, where MyDropDown is a component based on Material UI Dropdown component. If I don't provide any second parameter it looks like it returns a random Hash key instead of the provided MenuItem key.

Related

React custom Button component "as" prop

I want to add a feature to my Button component wherein I want to add an as prop just like in other component libraries to render different components based on the as value.

Render a new component onClick without using conditional rendering or react-router

Here is what I am trying to achieve. I have an MUI table that contains a list of data (say student names) and it is a Functional Component. When a user clicks on any of the items in the table, it should load the details of the student clicked in a card or a box. (MUI components). The card has a back button that loads back the same table when clicked. I'm not sure how to achieve it without using react-router or without using conditional rendering.
The doubt that I have is, do we need to hide the details component in render from the main page, till it's clicked on? Like the whole tree needs to carry this component from MainPage(Hide)-> Table(hide) -> Student details(display it on click). Do I need to hide it from the main component render and only change the prop onClick in the table component? I'm not sure if we have a better approach, where I can directly call it in the table component?
You can use custom MUI Modal component to load the details to achieve your requirement without the need of react-router.
And to toggle the Modal, you can use onClick handler on MUI TableRow. TableRow doesn't have onClick prop, but the underlying component is React's tr by default, which accepts onClick.

Moving placeholder text in Autocomplete component in React

I'm trying to create a Material UI's Autocomplete component. Instead of showing suggestions of Autocomplete as dropdown, How can I show it as moving placeholder? The text inside the Autocomplete component should slide in left?
Code: https://codesandbox.io/s/material-demo-forked-mgg7z?file=/demo.js
The search results (The Godfather) should have a slide in left motion as a placeholder.
I created a custom hook useAnimatedPlaceholder in this demo
https://codesandbox.io/s/material-demo-forked-2em32?file=/demo.js
It can be easily inserted into any input base components. The functionality is achieved via using the useEffect and setTimeout combo. Let me know if you have any questions.
You can also give a text field inside autocomplete.

How disable area-autocomplete

In my react app I used Formik form helper but it add area-autocomplete="list", when I try to add that prop react change my added value to "list" again on Focus. Even functions that change that prop didn't help.

how to clear selected checkboxes programatically from parent component

I have used the following component in react,
https://www.npmjs.com/package/react-multiselect-checkboxes
I want to clear selected checkboxes because I have to recreate it with new options from another dropdown change event.
So is there any way from where I can clear selected checkboxes from parent component when another dropdown is changed
This is for react
The author of the libarary suggest that its behavior is based on react-select
Have you tried to use value prop?
see https://github.com/JedWatson/react-select#controllable-props
Additionally if you want to manipulate values in parent component you should use onChange callback then and store it somewhere (I assume state will be best place)

Resources