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

Read-only text block for forms #13644

Closed
kirill-konshin opened this issue Nov 19, 2018 · 14 comments
Closed

Read-only text block for forms #13644

kirill-konshin opened this issue Nov 19, 2018 · 14 comments
Labels
component: text field This is the name of the generic UI component, not the React module! new feature New feature or request

Comments

@kirill-konshin
Copy link

kirill-konshin commented Nov 19, 2018

Quite frequently there's a need to display some value in the form, it could be achieved by making an input read only (there was a proposal to add read-only prop for TextField: #9790), but it would still have the underline, also, the presented text can have formatting, links, images, etc., which is impossible to do with input.

So far I used the following code as temp solution:

import {styles as inputBaseStyles} from '@material-ui/core/InputBase/InputBase';

const ReadOnly = withStyles(inputBaseStyles)(({children, classes, className, ...props}) => (
    <div className={cx(classes.root, className)} {...props}>
        <div className={classes.input}>{children}</div>
    </div>
));

So that it could be used as follows:

<FormControl>
    <InputLabel shrink>Label</InputLabel>
    <ReadOnly>Foo</ReadOnly>
</FormControl>

Does it make sense to add such component to the lib? Is it safe to use default styles like this?

PS. There is a special class in bootstrap for such case: http://getbootstrap.com/docs/4.1/components/forms/#readonly-plain-text

@kirill-konshin
Copy link
Author

Ping

@vileppanen
Copy link
Contributor

I'm not sure if I get this right:
You want to display read-only text field, with the Material styling?

Or you want to "display anything you want" but styled as if it was a Material styled text field?

@eps1lon eps1lon added the component: text field This is the name of the generic UI component, not the React module! label Feb 5, 2019
@eps1lon
Copy link
Member

eps1lon commented Feb 5, 2019

@kirill-konshin What was #9790 (comment) lacking?

Displaying an image in TextField would be a different issue. Do you mean something like adornments? Could you showcase such a use case?.

@eps1lon eps1lon added the new feature New feature or request label Feb 5, 2019
@kirill-konshin
Copy link
Author

I was not talking about adornments, I was looking for something that allows to display any content with an input label on top. The implementation that I've supplied to this ticket does exactly this.

@eps1lon
Copy link
Member

eps1lon commented Feb 5, 2019

But that's not really an input not even mentioning a textfield. It's just a generic container with a label. I was interested in a specific use case that relates to input provided by the user.

@kirill-konshin
Copy link
Author

Case 1. Read-only phrase with edit button
Case 2. Custom control like an MP3 player
Case 3. A checkbox or set of checkboxes or radios under common label

@kirill-konshin
Copy link
Author

image

Looks like this :)

@eps1lon
Copy link
Member

eps1lon commented Feb 5, 2019

Case 1. Read-only phrase with edit button

Sounds like #9790 (comment) would solve this. What is missing?

Case 2. Custom control like an MP3 player

That's very specific use case where an input is not the appropriate abstraction

Case 3. A checkbox or set of checkboxes or radios under common label

This should be covered by https://material-ui.com/demos/selection-controls/#radio-buttons

I feel like your example is perfectly fine. It's a generic container with a label.

@kirill-konshin
Copy link
Author

#9790 (comment) can only have text, no hyperlinks, no images, no custom tags, so this does not work.

Fieldset+legend (https://material-ui.com/demos/selection-controls/#radio-buttons) could be an option as a generic container with a label, but it has different visual style than a textfield's label, that's my main concern...

@kirill-konshin
Copy link
Author

@kirill-konshin
Copy link
Author

Actually, this issue is coupled with #13643, forgot to mention that )

@kirill-konshin
Copy link
Author

kirill-konshin commented Feb 5, 2019

Sorry for confusion.

This particular ticket is only about the ReadOnly container that looks like a read-only Input but can have rich formatting, not just text.

The container discussion is a separate ticket: #13643.

@oliviertassinari
Copy link
Member

This seems to be a duplicate of #9790. The readOnly prop is supposed to cover this problem.

@kirill-konshin
Copy link
Author

No, readOnly prop just makes field to become read only, it does not allow to have HTML markup in the block. I commented about that earlier in this thread:

#9790 (comment) can only have text, no hyperlinks, no images, no custom tags, so this does not work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: text field This is the name of the generic UI component, not the React module! new feature New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants