Skip to content
This repository has been archived by the owner on Oct 19, 2021. It is now read-only.

Commit

Permalink
fix: deprecate the appendTo prop in date picker (#2062)
Browse files Browse the repository at this point in the history
* fix: deprecate the appendTo prop in date picker

* fix: Add deprecation warning

* fix: typos in warning
  • Loading branch information
vpicone authored and jnm2377 committed Mar 21, 2019
1 parent fd92bfb commit b61211d
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/components/DatePicker/DatePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ import flatpickr from 'flatpickr';
import l10n from 'flatpickr/dist/l10n/index';
import rangePlugin from 'flatpickr/dist/plugins/rangePlugin';
import { settings } from 'carbon-components';
import warning from 'warning';
import DatePickerInput from '../DatePickerInput';
import Icon from '../Icon';
import { componentsX } from '../../internal/FeatureFlags';
import { componentsX, breakingChangesX } from '../../internal/FeatureFlags';

const { prefix } = settings;

Expand Down Expand Up @@ -251,10 +252,18 @@ export default class DatePicker extends Component {
const onHook = (electedDates, dateStr, instance) => {
this.updateClassNames(instance);
};
const appendToNode =
typeof appendTo === 'string'
? document.querySelector(appendTo)
: appendTo;

let appendToNode;
if (typeof appendTo === 'string' && !breakingChangesX) {
warning(
false,
`The DatePicker appendTo prop will be deprecated in Carbon X.
- If you were using appendTo for styling, consider using a className.
- If you were using appendTo for attaching to a specific DOM node, consider a React portal.`
);
appendToNode = document.querySelector(appendTo);
}

// inputField ref might not be set in enzyme tests
if (this.inputField) {
this.cal = new flatpickr(this.inputField, {
Expand Down

0 comments on commit b61211d

Please sign in to comment.