Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can a Material UI Date picker element be triggered from a Flat or Raised button element

Tags:

material-ui

I am trying to open the date picker dialog from a Raised button, which is inside a toolbar element, with no joy.

After going through the documentation I found no solution. I tried putting the Date picker inside the Flat Button like so:

<RaisedButton label="Start Date" onTouchTap={this.handleRaisedButtonTap} primary={true}>
   <DatePicker autoOk={true} formatDate={this.datePickerFormat} hintText='Start Date' label='Start Date' value={this.state.filter.startDate.display} />
</RaisedButton>

I would like to open the date picker dialog when the button is clicked.

Any help would be greatly appreciated

like image 484
Ash Shahabi Avatar asked Jan 06 '16 14:01

Ash Shahabi


People also ask

How to use material UI Pickers with datepicker?

For using the Datepicker component, we also need to install the Material UI Pickers package Install the date-io package to perform various basic date operations Note: For material-ui-pickers v3 use v1.x version of @date-io adapters. There are a number of UI components provided by Material UI package modules.

How to set date pickers in Mui?

You need to install 3 different types of package to make the pickers work: The component ( @mui/x-date-pickers or @mui/x-date-pickers-pro) manages the rendering. The date-library ( moment, dayjs, ...) manages the date manipulation. The adapter ( @date-io) exposes your favorite date-library under a unified api used by component.

Where is the date range picker in material-UI V5?

As part of Material-UI v5, the pickers are moving into @material-ui/lab ( next.material-ui.com/components/date-picker) and will likely experience some changes to the API while in the lab. @ Ryan will refrain from using it then. I need the date range picker, but it appears that material-ui is only making that available through its premium package.

How to change the style of the datepicker?

The variant property is used to change the style of the Datepicker. There are three types of variants available "dialog" (default), "inline" & "static" The static date picker is placed as an element and copies space. The Dialog variant is displayed in the center of the page, useful for mobile or small interfaces.


1 Answers

you have to open it from the refs of the DatePicker component

openDatePicker(){
  this.refs.dp.openDialog()
}

render(){
  return (
    <div>
      <RaisedButton onTouchTap={this.openDatePicker} label='open date picker' />
      <DatePicker ref='dp' />
    </div>
  )
}
like image 135
rkstar Avatar answered Jan 04 '23 01:01

rkstar