Comments (6)
thanks for your feedback @shoeman22 i will update the example as yours :)
from input.
<section>
<label>MUI Select (wrapped)</label>
<RHFInput
as={<WrappedSelect name="test" />}
name="WrappedSelect"
register={register}
setValue={setValue}
/>
</section>
have you try the above?
from input.
Yep, that looks like that approach would work as well for the value itself, but the other props aren't going to be sent down.
from input.
what do you mean other props?
<section>
<label>React Select</label>
<RHFInput
as={<ReactSelect />}
options={options}
name="ReactSelect"
{...methods}
isClearable // you can pass props here as well
/>
</section>
from input.
What I'd initially done was something like this:
// alternately, it could've been thought of as:
// const WrappedSelect = (propsFromRHFInputThatWereIgnored) => (
const WrappedSelect = () => (
<Select>
<MenuItem value={10}>Ten</MenuItem>
<MenuItem value={20}>Twenty</MenuItem>
<MenuItem value={30}>Thirty</MenuItem>
</Select>
);
return (
<RHFInput
as={<WrappedSelect />}
name="CountryId"
register={register}
setValue={setValue}
variant="outlined"
margin="normal" // bunch of material-ui Select props
/>
);
And I couldn't figure out why variant
, margin
, value
, etc. weren't getting applied to the Select
(material-ui was complaining about trying to set the value to undefined on the Select
). The problem was if you use a wrapper, RHFInput is actually cloning the wrapper element (WrappedSelect
) and it is getting the props passed down to it. So you need to forward those props that are coming in to the real Select
element in that case by passing the props down:
const WrappedSelect = (propsFromRHFInputImNowForwarding) => (
<Select {...propsFromRHFInputImNowForwarding}>
<MenuItem value={10}>Ten</MenuItem>
<MenuItem value={20}>Twenty</MenuItem>
<MenuItem value={30}>Thirty</MenuItem>
</Select>
);
from input.
sorry for the late reply. i do spread rest of the props to the as
component
return React.cloneElement(as, {
...(onChangeEvent
? {
[onChangeName || 'onChange']: eventWrapper(
onChangeEvent,
'onChange',
),
}
: { onChange: handleChange }),
...(isOnBlur
? onBlurEvent
? { [onBlurName || 'onBlur']: eventWrapper(onBlurEvent, 'onBlur') }
: { onBlur: handleBlur }
: {}),
value: value || inputValue,
...(isCheckbox ? { checked: inputValue } : {}),
...rest,
});
i am going to close this issue now, feel free to leave more questions and suggestions tho. 👍
from input.
Related Issues (20)
- RHFInput `as` props shows errors in TypeScript HOT 5
- RHFInput 'onBlur' mode deselects selected option when using React-Select HOT 5
- Issues with RHFInput and validation HOT 1
- When value is set to select, I can no longer select another value
- Type error about async validate function HOT 3
- Warning: A component is changing an uncontrolled input of type text to be controlled. HOT 2
- RHFInput + AntD TimePicker isn't working after 1.1.0 HOT 1
- Using RFHInput with MaterialUI TextField : `[object HTMLInputElement]` when empty HOT 1
- Question: Proper way of using RHFInput in MaterialUI custom component? HOT 4
- Lost selected option in Select component when value is 0 HOT 4
- Checkbox validation is not working as expected HOT 10
- AntD switch is not correctly if type is checkbox. HOT 4
- React Semantic UI modal with React Hook Form default values disappear HOT 8
- RHFInput type issue with setValue HOT 4
- Why always get a strange number when using the V4 version in ReactNative HOT 1
- RHF Input with React-Select Libary HOT 2
- export 'useFormContext' was not found in 'react-hook-form' HOT 1
- RHFInput + Semantic UI (Checkbox and Select) HOT 1
- Cursor AutoFocus to the end on editing text HOT 1
- Uncaught DOMException: Failed to set the 'value' property on 'HTMLInputElement': This input element accepts a filename, which may only be programmatically set to the empty string. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from input.