From a1622957b4d2961438f10a61784ff1366c536ec1 Mon Sep 17 00:00:00 2001 From: Arthur Denner Date: Sat, 9 May 2020 14:34:18 +0200 Subject: [PATCH 1/2] fix(datepicker): allow empty string as placeholder --- src/__tests__/datepicker.test.tsx | 20 ++++++++++++++++++++ src/index.tsx | 5 +++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/__tests__/datepicker.test.tsx b/src/__tests__/datepicker.test.tsx index c48c4fc3..27568ce1 100644 --- a/src/__tests__/datepicker.test.tsx +++ b/src/__tests__/datepicker.test.tsx @@ -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', () => { diff --git a/src/index.tsx b/src/index.tsx index 58e2a466..fd4c374b 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -83,7 +83,7 @@ class SemanticDatepicker extends React.Component< name: undefined, onBlur: () => {}, onChange: () => {}, - placeholder: null, + placeholder: undefined, pointing: 'left', readOnly: false, datePickerOnly: false, @@ -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, From 9bb1bdce46d17d99914aad948d230d20e3f204a1 Mon Sep 17 00:00:00 2001 From: Arthur Denner Date: Sat, 9 May 2020 14:36:17 +0200 Subject: [PATCH 2/2] chore: apply lint on stories folder --- package.json | 3 ++- stories/basic.stories.tsx | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index af5ee1a9..587058e7 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/stories/basic.stories.tsx b/stories/basic.stories.tsx index 77810bbe..1c63444e 100644 --- a/stories/basic.stories.tsx +++ b/stories/basic.stories.tsx @@ -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;