Material-ui: [TextField] Contributing solo field

Created on 12 Sep 2017  路  4Comments  路  Source: mui-org/material-ui

  • [x] I have searched the issues of this repository and believe that this is not a duplicate.

I was thinking I could contribute a "solo field" to Material UI, if you're interested, and given you don't already have a solution for it already. The idea is to have a input field that can be used as the main search form in webapps. I have created a custom one that I use together with material-ui, and figured it would be cool to make a contribution to the project.

First of all, does it make sense to have this as a component or is the idea that it is easy enough to change the existing TextField / AutoComplete components with the new classes API and withStyles HOC?

Second, I was thinking of making it a separate component, but perhaps it's better to include it in the existing TextField component? Thoughts? Actually, when I think about it, it definitely needs to support auto-complete, so on a second thought it should probably rely on AutoComplete (which I assume in turn is based on TextField).

It should support an icon (and potentially a drop down menu) and auto-complete.

Examples:

Screenshot examples:

Floating toolbar with solo field:
image

Regular toolbar/app bar with solo field:
image

TextField enhancement

Most helpful comment

Vuetify has a solo field but given the composition capability we have, I'm not sure we need more than a demo:

capture d ecran 2018-12-18 a 21 59 07

import React from "react";
import PropTypes from "prop-types";
import { withStyles } from "@material-ui/core/styles";
import Paper from "@material-ui/core/Paper";
import InputBase from "@material-ui/core/InputBase";
import IconButton from "@material-ui/core/IconButton";
import MenuIcon from "@material-ui/icons/Menu";

const styles = theme => ({
  root: {
    padding: "2px 4px"
  },
  input: {
    marginLeft: 4
  }
});

function PaperSheet(props) {
  const { classes } = props;

  return (
    <Paper className={classes.root} elevation={1}>
      <IconButton className={classes.menuButton} aria-label="Menu">
        <MenuIcon />
      </IconButton>
      <InputBase className={classes.input} placeholder="Search Google Maps" />
    </Paper>
  );
}

PaperSheet.propTypes = {
  classes: PropTypes.object.isRequired
};

export default withStyles(styles)(PaperSheet);

https://codesandbox.io/s/pjq9nrmkqx

All 4 comments

@lirbank Hey, before all, thank for your interest in the project!

First of all, does it make sense to have this as a component

I'm not 100% sure about what you are referring to but I do think that a new component would be the best approach. The closest thing we have so far is a custom component I have been writing to host the Algolia search:
capture d ecran 2017-09-13 a 20 57 23

I would love to see the global architecture you are proposing (API, component structure). You said that you have already been building one component for an in-house use case. Maybe you could be sharing it on codesandbox.io so we have a better idea about the component :).

Does this need more than maybe a styling option on Textfield otherwise it's just a Paper, Toolbar, Buttons and TextField isn't it? All we would do is replace these generic components with the more specific ones. Only advantage I can see would be to handle the responsive aspects of the design guidelines automatically. Perhaps a demo in the docs would be sufficient?

@oliviertassinari Is this needed anymore?

Vuetify has a solo field but given the composition capability we have, I'm not sure we need more than a demo:

capture d ecran 2018-12-18 a 21 59 07

import React from "react";
import PropTypes from "prop-types";
import { withStyles } from "@material-ui/core/styles";
import Paper from "@material-ui/core/Paper";
import InputBase from "@material-ui/core/InputBase";
import IconButton from "@material-ui/core/IconButton";
import MenuIcon from "@material-ui/icons/Menu";

const styles = theme => ({
  root: {
    padding: "2px 4px"
  },
  input: {
    marginLeft: 4
  }
});

function PaperSheet(props) {
  const { classes } = props;

  return (
    <Paper className={classes.root} elevation={1}>
      <IconButton className={classes.menuButton} aria-label="Menu">
        <MenuIcon />
      </IconButton>
      <InputBase className={classes.input} placeholder="Search Google Maps" />
    </Paper>
  );
}

PaperSheet.propTypes = {
  classes: PropTypes.object.isRequired
};

export default withStyles(styles)(PaperSheet);

https://codesandbox.io/s/pjq9nrmkqx

Was this page helpful?
0 / 5 - 0 ratings