Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,19 @@ More examples [here](https://react-semantic-ui-datepickers.now.sh).

### Own Props

| property | type | required | default | description |
| ---------------- | ------------------- | -------- | ------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------- |
| clearable | boolean | no | true | Allows the user to clear the value |
| format | string | no | 'YYYY-MM-DD' | Specifies how the date will be formatted using the [date-fns' format](https://date-fns.org/v1.29.0/docs/format) |
| keepOpenOnClear | boolean | no | false | Keeps the datepicker open (or opens it if it's closed) when the clear icon is clicked |
| keepOpenOnSelect | boolean | no | false | Keeps the datepicker open when a date is selected |
| locale | object | no | [en-US](https://github.com/arthurdenner/react-semantic-ui-datepickers/blob/master/src/locales/en-US.js) | Object with the labels to be used on the library PS: Feel free to submit PR's with more locales! |
| onDateChange | function | yes | | Callback fired when the value changes |
| type | string | no | basic | Type of input to render. Available options: 'basic' and 'range' |
| filterDate | function | no | () => true | Function that receives each date and returns a boolean to indicate whether it is enabled or not |
| selected | Date, arrayOf(Date) | no | | Default date selected |
| pointing | string | no | 'left' | Location to render the component around input. Available options: 'left', 'right', 'top left', 'top right' |
| property | type | required | default | description |
| -------------------- | ------------------- | -------- | ------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------- |
| clearable | boolean | no | true | Allows the user to clear the value |
| format | string | no | 'YYYY-MM-DD' | Specifies how the date will be formatted using the [date-fns' format](https://date-fns.org/v1.29.0/docs/format) |
| keepOpenOnClear | boolean | no | false | Keeps the datepicker open (or opens it if it's closed) when the clear icon is clicked |
| keepOpenOnSelect | boolean | no | false | Keeps the datepicker open when a date is selected |
| locale | object | no | [en-US](https://github.com/arthurdenner/react-semantic-ui-datepickers/blob/master/src/locales/en-US.js) | Object with the labels to be used on the library PS: Feel free to submit PR's with more locales! |
| onDateChange | function | yes | | Callback fired when the value changes |
| type | string | no | basic | Type of input to render. Available options: 'basic' and 'range' |
| filterDate | function | no | () => true | Function that receives each date and returns a boolean to indicate whether it is enabled or not |
| selected | Date, arrayOf(Date) | no | | Default date selected |
| pointing | string | no | 'left' | Location to render the component around input. Available options: 'left', 'right', 'top left', 'top right' |
| clearOnSameDateClick | boolean | no | true | Controls whether the datepicker's state resets if the same date is selected in succession. |

### Form.Input Props

Expand Down
26 changes: 22 additions & 4 deletions src/components/datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class SemanticDatepicker extends React.Component {
format: PropTypes.string,
keepOpenOnClear: PropTypes.bool,
keepOpenOnSelect: PropTypes.bool,
clearOnSameDateClick: PropTypes.bool,
locale: PropTypes.object,
onBlur: PropTypes.func,
onDateChange: PropTypes.func.isRequired,
Expand All @@ -83,6 +84,7 @@ class SemanticDatepicker extends React.Component {
format: 'YYYY-MM-DD',
keepOpenOnClear: false,
keepOpenOnSelect: false,
clearOnSameDateClick: true,
locale: localeEn,
onBlur: () => {},
placeholder: null,
Expand Down Expand Up @@ -222,11 +224,28 @@ class SemanticDatepicker extends React.Component {
};

handleBasicInput = newDate => {
const { format, keepOpenOnSelect, onDateChange } = this.props;
const {
format,
keepOpenOnSelect,
onDateChange,
clearOnSameDateClick,
} = this.props;

if (!newDate) {
this.resetState();

// if clearOnSameDateClick is true (this is the default case)
// then reset the state. This is what was previously the default
// behavior, without a specific prop.
if (clearOnSameDateClick) {
this.resetState();
} else {
// Don't reset the state. Instead, close or keep open the
// datepicker according to the value of keepOpenOnSelect.
// Essentially, follow the default behavior of clicking a date
// but without changing the value in state.
this.setState({
isVisible: keepOpenOnSelect,
});
}
return;
}

Expand Down Expand Up @@ -322,7 +341,6 @@ class SemanticDatepicker extends React.Component {
typedValue,
} = this.state;
const { clearable, locale, pointing, filterDate } = this.props;

return (
<div
className="field"
Expand Down
10 changes: 9 additions & 1 deletion stories/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,19 @@ storiesOf('Examples', module)
<SemanticDatepicker onDateChange={console.log} />
</Content>
))
.add('Basic Readonly', () => (
.add('Basic with readOnly', () => (
<Content>
<SemanticDatepicker onDateChange={console.log} readOnly={true} />
</Content>
))
.add('Basic with clearOnSameDateClick={false}', () => (
<Content>
<SemanticDatepicker
onDateChange={console.log}
clearOnSameDateClick={false}
/>
</Content>
))
.add('Basic with allowOnlyNumbers', () => (
<Content>
<SemanticDatepicker allowOnlyNumbers onDateChange={console.log} />
Expand Down