Skip to content

Commit

Permalink
Adds title attribute to clear button (Hacker0x01#1317)
Browse files Browse the repository at this point in the history
* Adds title attribute to clear button

* Changes title attribute to be configurable, adds test, updates docs

* Updates clear button to be a button and removes it from tab order
  • Loading branch information
nateha1984 authored and martijnrusschen committed Mar 31, 2018
1 parent 5eee56f commit 988c28d
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 4 deletions.
1 change: 1 addition & 0 deletions docs/datepicker.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'` | |
Expand Down
8 changes: 5 additions & 3 deletions src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -588,10 +589,11 @@ export default class DatePicker extends React.Component {
renderClearButton = () => {
if (this.props.isClearable && this.props.selected != null) {
return (
<a
<button
className="react-datepicker__close-icon"
href="javascript:void(0)"
onClick={this.onClearClick}
title={this.props.clearButtonTitle}
tabIndex={-1}
/>
);
} else {
Expand Down
15 changes: 15 additions & 0 deletions test/datepicker_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
<DatePicker
selected={utils.newDate("2018-03-19")}
isClearable
clearButtonTitle="clear button"
/>
);
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;
Expand Down
13 changes: 12 additions & 1 deletion test/week_number_test.js
Original file line number Diff line number Diff line change
@@ -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(<WeekNumber weekNumber={weekNumber} {...props} />);
}

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(
<WeekNumber weekNumber={1} onClick={onClick} />
);
shallowWeekNumber.instance().handleClick({});
expect(onClick).to.have.property("callCount", 1);
});
});
});

0 comments on commit 988c28d

Please sign in to comment.