diff --git a/docs/datepicker.md b/docs/datepicker.md index fe3918aad..75dcb3564 100644 --- a/docs/datepicker.md +++ b/docs/datepicker.md @@ -10,6 +10,7 @@ General datepicker component. | `calendarClassName` | `string` | | | | `children` | `node` | | | | `className` | `string` | | | +| `clearButtonTitle` | `string` | | | | `customInput` | `element` | | | | `customInputRef` | `string` | `'ref'` | The property used to pass the ref callback | | `dateFormat` | `union(string\|array)` | `'L'` | | diff --git a/src/index.jsx b/src/index.jsx index 4258c6ed2..d76c94e09 100644 --- a/src/index.jsx +++ b/src/index.jsx @@ -128,7 +128,8 @@ export default class DatePicker extends React.Component { minTime: PropTypes.object, maxTime: PropTypes.object, excludeTimes: PropTypes.array, - useShortMonthInDropdown: PropTypes.bool + useShortMonthInDropdown: PropTypes.bool, + clearButtonTitle: PropTypes.string }; static get defaultProps() { @@ -588,10 +589,11 @@ export default class DatePicker extends React.Component { renderClearButton = () => { if (this.props.isClearable && this.props.selected != null) { return ( - ); } else { diff --git a/test/datepicker_test.js b/test/datepicker_test.js index 76b3efb2c..f0a9030d2 100644 --- a/test/datepicker_test.js +++ b/test/datepicker_test.js @@ -337,6 +337,21 @@ describe("DatePicker", () => { expect(datePicker.state.inputValue).to.be.null; }); + it("should set the title attribute on the clear button if clearButtonTitle is supplied", () => { + const datePicker = TestUtils.renderIntoDocument( + + ); + const clearButtonText = TestUtils.findRenderedDOMComponentWithClass( + datePicker, + "react-datepicker__close-icon" + ).getAttribute("title"); + expect(clearButtonText).to.equal("clear button"); + }); + it("should save time from the selected date", () => { const selected = utils.newDate("2015-12-20 10:11:12"); let date; diff --git a/test/week_number_test.js b/test/week_number_test.js index dc739fc62..f2f6240e8 100644 --- a/test/week_number_test.js +++ b/test/week_number_test.js @@ -1,20 +1,31 @@ import React from "react"; import WeekNumber from "../src/week_number"; import { shallow } from "enzyme"; +import sinon from "sinon"; function renderWeekNumber(weekNumber, props = {}) { return shallow(); } describe("WeekNumber", () => { + let shallowWeekNumber; describe("rendering", () => { it("should render the specified Week Number", () => { const weekNumber = 1; - const shallowWeekNumber = renderWeekNumber(weekNumber); + shallowWeekNumber = renderWeekNumber(weekNumber); expect( shallowWeekNumber.hasClass("react-datepicker__week-number") ).to.equal(true); expect(shallowWeekNumber.text()).to.equal(weekNumber + ""); }); + + it("should call the onClick function if it is defined", () => { + const onClick = sinon.spy(); + shallowWeekNumber = shallow( + + ); + shallowWeekNumber.instance().handleClick({}); + expect(onClick).to.have.property("callCount", 1); + }); }); });