Skip to content

Commit

Permalink
fix(DatePicker): remove decorative svg as a click target (#10283)
Browse files Browse the repository at this point in the history
* fix(DatePicker): remove decorative svg as a click target

* test(datepicker): remove usages of removed openCalendar prop, mirror style changes

* fix(DatePicker): add deprecation warnings for unneeded props

* test(DatePicker): update snapshot tests

* fix(datepicker): no longer call deprecated openCalendar input prop

Co-authored-by: Taylor Jones <[email protected]>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Dec 17, 2021
1 parent 334821f commit 7be55cd
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@
// vertically center icon within parent container on IE11
top: 50%;
right: 1rem;
cursor: pointer;
fill: $icon-primary;
pointer-events: none;
transform: translateY(-50%);
}

Expand Down
8 changes: 2 additions & 6 deletions packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2502,9 +2502,7 @@ Map {
"hideLabel": Object {
"type": "bool",
},
"iconDescription": Object {
"type": "string",
},
"iconDescription": [Function],
"id": Object {
"isRequired": true,
"type": "string",
Expand All @@ -2525,9 +2523,7 @@ Map {
"onClick": Object {
"type": "func",
},
"openCalendar": Object {
"type": "func",
},
"openCalendar": [Function],
"pattern": [Function],
"placeholder": Object {
"type": "string",
Expand Down
15 changes: 0 additions & 15 deletions packages/react/src/components/DatePicker/DatePicker-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,21 +354,6 @@ describe('DatePicker', () => {
});
});

describe('DatePickerInput', () => {
it('should call `openCalendar` on calendar icon click', () => {
const mockOpenCalendar = jest.fn();
const wrapper = mount(
<DatePickerInput
labelText="Date Picker label"
id="input-from"
openCalendar={mockOpenCalendar}
/>
);
wrapper.find('svg').simulate('click');
expect(mockOpenCalendar).toHaveBeenCalled();
});
});

describe('DatePickerSkeleton', () => {
describe('Renders as expected', () => {
const wrapper = shallow(<DatePickerSkeleton range />);
Expand Down
8 changes: 0 additions & 8 deletions packages/react/src/components/DatePicker/DatePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -529,12 +529,6 @@ export default class DatePicker extends Component {
</svg>`;
}

openCalendar = () => {
if (this.cal) {
this.cal.open();
}
};

updateClassNames = (calendar) => {
const calendarContainer = calendar.calendarContainer;
const daysContainer = calendar.days;
Expand Down Expand Up @@ -660,7 +654,6 @@ export default class DatePicker extends Component {
return React.cloneElement(child, {
datePickerType,
ref: this.assignInputFieldRef,
openCalendar: this.openCalendar,
});
}
if (
Expand All @@ -671,7 +664,6 @@ export default class DatePicker extends Component {
return React.cloneElement(child, {
datePickerType,
ref: this.assignToInputFieldRef,
openCalendar: this.openCalendar,
});
}
if (index === 0) {
Expand Down
14 changes: 11 additions & 3 deletions packages/react/src/components/DatePickerInput/DatePickerInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import PropTypes from 'prop-types';
import React, { Component } from 'react';
import deprecate from '../../prop-types/deprecate';
import classNames from 'classnames';
import { settings } from 'carbon-components';
import {
Expand Down Expand Up @@ -46,7 +47,10 @@ export default class DatePickerInput extends Component {
/**
* The description of the calendar icon.
*/
iconDescription: PropTypes.string,
iconDescription: deprecate(
PropTypes.string,
`\nThe prop \`iconDescriptionInput\` for DatePickerInput has been deprecated and is no longer used`
),

/**
* Specify an id that uniquely identifies the `<input>`
Expand Down Expand Up @@ -83,7 +87,10 @@ export default class DatePickerInput extends Component {
/**
* Provide a function to be called when the input field is clicked
*/
openCalendar: PropTypes.func,
openCalendar: deprecate(
PropTypes.func,
`\nThe prop \`openCalendar\` for DatePickerInput has been deprecated and is no longer used`
),

/**
* Provide a regular expression that the input value must match
Expand Down Expand Up @@ -220,7 +227,8 @@ export default class DatePickerInput extends Component {
className={`${prefix}--date-picker__icon`}
aria-label={iconDescription}
onClick={openCalendar}
role="img">
role="img"
aria-hidden="true">
{iconDescription && <title>{iconDescription}</title>}
</Calendar16>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@
// vertically center icon within parent container on IE11
top: 50%;
right: 1rem;
cursor: pointer;
fill: $icon-primary;
pointer-events: none;
transform: translateY(-50%);
}

Expand Down

0 comments on commit 7be55cd

Please sign in to comment.