Skip to content

Instantly share code, notes, and snippets.

@prescod
Created March 26, 2019 04:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prescod/724c19066b8aa206a6d210c15b077596 to your computer and use it in GitHub Desktop.
Save prescod/724c19066b8aa206a6d210c15b077596 to your computer and use it in GitHub Desktop.
Datepicker issues.
/* eslint-disable no-console, react/prop-types */
import React, { Component, useState } from 'react';
import logo from './logo.svg';
import './App.css';
import {IconSettings, Datepicker, Button} from '@salesforce/design-system-react';
class Example extends React.Component {
static displayName = 'DatepickerExample';
constructor(props) {
super(props);
this.state = {curDate: new Date()};
}
render() {
console.log("Curdate", this.state.curDate);
return (
<React.Fragment>
<Datepicker
value = {this.state.curDate}
onChange={(event, data) => {
if (this.props.action) {
const dataAsArray = Object.keys(data).map((key) => data[key]);
this.props.action('onChange')(event, data, ...dataAsArray);
} else if (console) {
console.log('onChange', event, data);
}
}}
onCalendarFocus={(event, data) => {
if (this.props.action) {
const dataAsArray = Object.keys(data).map((key) => data[key]);
this.props.action('onCalendarFocus')(event, data, ...dataAsArray);
} else if (console) {
console.log('onCalendarFocus', event, data);
}
}}
/>
<Button onClick={()=>this.setState({curDate: null})}>Reset</Button>
<Button onClick={()=>this.setState({curDate: undefined})}>Reset with undefined</Button>
<Button onClick={()=>this.setState({curDate: ""})}>Reset with empty string</Button>
</React.Fragment>
);
}
}
class App extends Component {
render() {
return (
<div className="App">
<Example />
</div>
);
}
}
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment