-
Notifications
You must be signed in to change notification settings - Fork 47.8k
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
Bug: React 19 <input type="radio"/>
attribute name
can't be set via ref
#32346
Comments
There are generally no guarantees for manual DOM mutations targetting elements that are managed by React. And re-render could change manually set attributes back to the React managed value. Why do you need to manually set those DOM properties instead of letting React handle those values? |
We build a Design System with Mitosis, which will generate multiple targets To use the same code for every framework it was a good approach to use the DOM because that's the base for all of them. And it works for React 18 without any issue. My current issue comes from our Composition <DBTabs>
<DBTabList>
<DBTabItem>Tab 1</DBTabItem>
<DBTabItem>Tab 2</DBTabItem>
<DBTabItem>Tab 3</DBTabItem>
</DBTabList>
<DBTabPanel>Tab Panel 1</DBTabPanel>
<DBTabPanel>Tab Panel 2</DBTabPanel>
<DBTabPanel>Tab Panel 3</DBTabPanel>
</DBTabs> or Configuration <DBTabs tabs={[
{label: "Tab 1", content:"Tab Panel 1"},
{label: "Tab 2", content:"Tab Panel 2"},
{label: "Tab 3", content:"Tab Panel 3"}
]}> In the I'm wondering why it works in React 18, and why custom attributes like |
Problem
Solution
const App = () => {
return (
<div>
<label>
<input id="radio1" type="radio" name="radio-group" data-name="radio-group" />
Radio1
</label>
<label>
<input id="radio2" type="radio" name="radio-group" data-name="radio-group" />
Radio2
</label>
<label>
<input id="radio3" type="radio" name="radio-group" data-name="radio-group" />
Radio3
</label>
</div>
);
};
export default App;
import { useState } from "react";
const App = () => {
const [name] = useState("radio-group");
return (
<div>
<label>
<input id="radio1" type="radio" name={name} data-name={name} />
Radio1
</label>
<label>
<input id="radio2" type="radio" name={name} data-name={name} />
Radio2
</label>
<label>
<input
id="radio3"
type="radio"
name={name}
data-name={name}
/>
Radio3
</label>
</div>
);
};
export default App; |
I understand the concepts of React and agree, in general you should do it with a state in React. If the intention is that Moreover, I'm not deeply familiar with the React code, but somehow you need to keep the internal state to pass it to the DOM. Otherwise, the |
React version: 19
Steps To Reproduce
name
attributename
is removed from inputLink to code example: stackblitz
or GitHub repo
The current behavior
Adding
name
viauseRef
like:radio1.current.name = "radio-group";
orradio2.current.setAttribute("name", "radio-group");
adds the correct DOM attribute. The' name' attribute is removed by clicking on the<input>
. Other attributes likedata-name
are still on the element.The expected behavior
The
name
shouldn't be deleted when clicking on the input. It works with React v18 and it works if I add thename
directly on<input name="radio-group"/>
.The text was updated successfully, but these errors were encountered: