Skip to content
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

attributesToProps converts attribute with key name "open" always to value true #1165

Closed
michalpuskel opened this issue Nov 10, 2023 · 2 comments
Assignees
Labels
wontfix This will not be worked on

Comments

@michalpuskel
Copy link

import { attributesToProps } from 'html-react-parser';

const OBJ = { open_t: true, open_f: true, open: false, undefined_val: undefined, null_val: null };
console.log('@@ attributesToProps', attributesToProps(OBJ as any));
console.log('@@ OBJ', OBJ);

Snímka obrazovky 2023-11-10 o 13 03 32

Expected Behavior

value open should be false after attributesToProps conversion

Actual Behavior

keyword open for attribute name is hardcoded so that value is always true

Steps to Reproduce

convert object with attribute of name open with any falsy value (false, undefined, null, "")

Reproducible Demo

https://codesandbox.io/s/adoring-waterfall-rcr5fm?file=/src/App.tsx

Environment

"html-react-parser": "^5.0.3",

Keywords

attributesToProps, React, MUI, open, always true, hardcoded, html-react-parser

@michalpuskel michalpuskel added the bug Something isn't working label Nov 10, 2023
@michalpuskel michalpuskel changed the title attributesToProps converts attribute key with name "open" always to true attributesToProps converts attribute with key name "open" always to value true Nov 10, 2023
@remarkablemark
Copy link
Owner

@michalpuskel thanks for opening the issue! This is expected behavior as the open attribute is a boolean attribute so if the key exists, it will be considered true. See https://stackoverflow.com/a/15261366

@remarkablemark remarkablemark added wontfix This will not be worked on and removed bug Something isn't working labels Nov 10, 2023
@michalpuskel
Copy link
Author

Hi, OK thank you for explanation and quick response.

Though it is unfortunate in my use case with MUI Dialog https://mui.com/material-ui/api/dialog/
with required boolean attribute open to show / hide Dialog.

Nevertheless, never mind because I had to hard code Dialog with open true anyway and show / hide it with JS + CSS because rerendering works (or doesn't) the other way in templates than in regular React...

Cheers :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants