Skip to content

Commit e9cd679

Browse files
authored
fix(datepicker): allow empty string as placeholder (#261)
* fix(datepicker): allow empty string as placeholder * chore: apply lint on stories folder
1 parent 50b5895 commit e9cd679

File tree

4 files changed

+26
-4
lines changed

4 files changed

+26
-4
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"module": "dist/react-semantic-ui-datepickers.esm.js",
77
"typings": "dist/index.d.ts",
88
"scripts": {
9-
"lint": "tsdx lint src",
9+
"lint": "tsdx lint src stories",
10+
"lint:fix": "yarn lint --fix",
1011
"start": "tsdx watch",
1112
"build": "tsdx build",
1213
"prebuild": "rimraf dist",

src/__tests__/datepicker.test.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,26 @@ describe('Basic datepicker', () => {
266266
expect(onBlur).not.toHaveBeenCalled();
267267
});
268268
});
269+
270+
describe('placeholder', () => {
271+
it('should use the format prop as default', () => {
272+
const { datePickerInput } = setup();
273+
274+
expect(datePickerInput.placeholder).toBe('YYYY-MM-DD');
275+
});
276+
277+
it('should allow empty strings', () => {
278+
const { datePickerInput } = setup({ placeholder: '' });
279+
280+
expect(datePickerInput.placeholder).toBe('');
281+
});
282+
283+
it('should allow null', () => {
284+
const { datePickerInput } = setup({ placeholder: null });
285+
286+
expect(datePickerInput.placeholder).toBe('');
287+
});
288+
});
269289
});
270290

271291
describe('Range datepicker', () => {

src/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class SemanticDatepicker extends React.Component<
8383
name: undefined,
8484
onBlur: () => {},
8585
onChange: () => {},
86-
placeholder: null,
86+
placeholder: undefined,
8787
pointing: 'left',
8888
readOnly: false,
8989
datePickerOnly: false,
@@ -131,7 +131,8 @@ class SemanticDatepicker extends React.Component<
131131

132132
get inputProps() {
133133
const props = pick(semanticInputProps, this.props);
134-
const placeholder = props.placeholder || this.props.format;
134+
const placeholder =
135+
props.placeholder !== undefined ? props.placeholder : this.props.format;
135136

136137
return {
137138
...props,

stories/basic.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import SemanticDatepicker from '../src';
66
import { Content } from './common';
77
import { parseISO } from 'date-fns';
88

9-
const isWeekday = date => {
9+
const isWeekday = (date: Date) => {
1010
const day = date.getDay();
1111

1212
return day !== 0 && day !== 6;

0 commit comments

Comments
 (0)