Skip to content

Commit 0a65959

Browse files
authored
fix(datepicker): enable showToday prop to be provided on TypeScript (#306)
* fix(datepicker): enable showToday prop to be provided on TypeScript * test(datepicker): add tests for showToday prop * chore(deps): add resolutions to handlebars package * ci(Travis): update config to use Yarn instead of npm * ci(Codecov): add config to setup targets
1 parent d0e1073 commit 0a65959

File tree

12 files changed

+132
-32
lines changed

12 files changed

+132
-32
lines changed

.codecov.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
coverage:
2+
status:
3+
project:
4+
default:
5+
target: 75
6+
patch:
7+
default:
8+
target: 0

.travis.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
language: node_js
2-
cache:
3-
directories:
4-
- ~/.npm
2+
cache: yarn
53
notifications:
64
email: false
75
node_js: '10'
8-
install: npm install
9-
script: npm run validate
6+
install: yarn --frozen-lockfile
7+
script: yarn validate
108
after_success:
119
- npx codecov --disable=gcov
1210
- test $TRAVIS_BRANCH = "master" && test $TRAVIS_PULL_REQUEST = "false" && npx semantic-release

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ More examples [here](https://react-semantic-ui-datepickers.now.sh).
9191
| onBlur | function | no | () => {} | Callback fired when the input loses focus |
9292
| onChange | function | no | () => {} | Callback fired when the value changes |
9393
| pointing | string | no | 'left' | Location to render the component around input. Available options: 'left', 'right', 'top left', 'top right' |
94+
| showToday | boolean | no | true | Hides the "Today" button if false |
9495
| type | string | no | basic | Type of input to render. Available options: 'basic' and 'range' |
9596
| value | Date\|Date[] | no | -- | The value of the datepicker |
9697

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@
7979
"react": ">=16.8.0",
8080
"semantic-ui-react": ">=0.75.0"
8181
},
82+
"resolutions": {
83+
"handlebars" : "4.5.0"
84+
},
8285
"jest": {
8386
"globals": {
8487
"ts-jest": {

src/__tests__/datepicker.test.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,20 @@ describe('Basic datepicker', () => {
291291
expect(datePickerInput.placeholder).toBe('');
292292
});
293293
});
294+
295+
describe('showToday', () => {
296+
it('should display the Today button when prop is true', () => {
297+
const { getByText } = setup({ inline: true, showToday: true });
298+
299+
expect(getByText('Today')).toBeInTheDocument();
300+
});
301+
302+
it('should NOT display the Today button when prop is true', () => {
303+
const { queryByText } = setup({ inline: true, showToday: false });
304+
305+
expect(queryByText('Today')).not.toBeInTheDocument();
306+
});
307+
});
294308
});
295309

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

src/components/calendar/calendar.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
background-color: rgba(0, 0, 0, 0.1);
3131
border: 1px solid rgba(0, 0, 0, 0.1);
3232
border-radius: 0.28571429rem;
33+
overflow: hidden;
3334
}
3435

3536
.clndr-left {

src/components/calendar/calendar.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ type CalendarProps = {
2323
pointing: SemanticDatepickerProps['pointing'];
2424
previousMonth: string;
2525
previousYear: string;
26-
showToday: boolean;
26+
showToday: SemanticDatepickerProps['showToday'];
2727
todayButton: string;
2828
weekdays: Locale['weekdays'];
2929
};
@@ -163,9 +163,4 @@ const Calendar: React.FC<CalendarProps> = ({
163163
</Segment>
164164
);
165165

166-
Calendar.defaultProps = {
167-
pointing: 'left',
168-
showToday: true,
169-
};
170-
171166
export default Calendar;

src/components/icon.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,4 @@ const CustomIcon = ({
4747
);
4848
};
4949

50-
CustomIcon.defaultProps = {
51-
clearIcon: 'close',
52-
icon: 'calendar',
53-
};
54-
5550
export default CustomIcon;

src/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,14 @@ class SemanticDatepicker extends React.Component<
7070
> {
7171
static defaultProps = {
7272
allowOnlyNumbers: false,
73+
clearIcon: 'close',
7374
clearOnSameDateClick: true,
7475
clearable: true,
7576
date: undefined,
7677
filterDate: () => true,
7778
firstDayOfWeek: 0,
7879
format: 'YYYY-MM-DD',
80+
icon: 'calendar',
7981
id: undefined,
8082
inline: false,
8183
keepOpenOnClear: false,
@@ -90,6 +92,7 @@ class SemanticDatepicker extends React.Component<
9092
readOnly: false,
9193
datePickerOnly: false,
9294
required: false,
95+
showToday: true,
9396
showOutsideDays: false,
9497
type: 'basic',
9598
value: null,

src/types/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ export type SemanticDatepickerProps = PickedDayzedProps &
7272
data: SemanticDatepickerProps
7373
) => void;
7474
pointing: 'left' | 'right' | 'top left' | 'top right';
75+
showToday: boolean;
7576
type: 'basic' | 'range';
7677
datePickerOnly: boolean;
7778
value: DayzedProps['selected'];

0 commit comments

Comments
 (0)