Skip to content

Commit

Permalink
fix(datepicker): allow empty string as placeholder (#261)
Browse files Browse the repository at this point in the history
* fix(datepicker): allow empty string as placeholder

* chore: apply lint on stories folder
  • Loading branch information
arthurdenner committed May 9, 2020
1 parent 50b5895 commit e9cd679
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"module": "dist/react-semantic-ui-datepickers.esm.js",
"typings": "dist/index.d.ts",
"scripts": {
"lint": "tsdx lint src",
"lint": "tsdx lint src stories",
"lint:fix": "yarn lint --fix",
"start": "tsdx watch",
"build": "tsdx build",
"prebuild": "rimraf dist",
Expand Down
20 changes: 20 additions & 0 deletions src/__tests__/datepicker.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,26 @@ describe('Basic datepicker', () => {
expect(onBlur).not.toHaveBeenCalled();
});
});

describe('placeholder', () => {
it('should use the format prop as default', () => {
const { datePickerInput } = setup();

expect(datePickerInput.placeholder).toBe('YYYY-MM-DD');
});

it('should allow empty strings', () => {
const { datePickerInput } = setup({ placeholder: '' });

expect(datePickerInput.placeholder).toBe('');
});

it('should allow null', () => {
const { datePickerInput } = setup({ placeholder: null });

expect(datePickerInput.placeholder).toBe('');
});
});
});

describe('Range datepicker', () => {
Expand Down
5 changes: 3 additions & 2 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class SemanticDatepicker extends React.Component<
name: undefined,
onBlur: () => {},
onChange: () => {},
placeholder: null,
placeholder: undefined,
pointing: 'left',
readOnly: false,
datePickerOnly: false,
Expand Down Expand Up @@ -131,7 +131,8 @@ class SemanticDatepicker extends React.Component<

get inputProps() {
const props = pick(semanticInputProps, this.props);
const placeholder = props.placeholder || this.props.format;
const placeholder =
props.placeholder !== undefined ? props.placeholder : this.props.format;

return {
...props,
Expand Down
2 changes: 1 addition & 1 deletion stories/basic.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import SemanticDatepicker from '../src';
import { Content } from './common';
import { parseISO } from 'date-fns';

const isWeekday = date => {
const isWeekday = (date: Date) => {
const day = date.getDay();

return day !== 0 && day !== 6;
Expand Down

1 comment on commit e9cd679

@vercel
Copy link

@vercel vercel bot commented on e9cd679 May 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.