Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions output/components.eslint.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@
/home/travis/build/Talend/ui/packages/components/src/DateTimePickers/DateTimeRange/Manager/Manager.component.js
26:5 warning React Hook useEffect has missing dependencies: 'state.endDateTime' and 'state.startDateTime'. Either include them or remove the dependency array react-hooks/exhaustive-deps

/home/travis/build/Talend/ui/packages/components/src/DateTimePickers/InputDatePicker/InputDatePicker.component.js
67:6 error Static HTML elements with event handlers require a role jsx-a11y/no-static-element-interactions
108:2 error defaultProp "required" has no corresponding propTypes declaration react/default-props-match-prop-types

/home/travis/build/Talend/ui/packages/components/src/DateTimePickers/InputDateTimePicker/InputDateTimePicker.component.js
91:2 error defaultProp "required" has no corresponding propTypes declaration react/default-props-match-prop-types

Expand Down Expand Up @@ -307,5 +303,5 @@
673:44 error ["icon"] is better written in dot notation dot-notation
679:56 error ["resizable"] is better written in dot notation dot-notation

148 problems (128 errors, 20 warnings)
146 problems (126 errors, 20 warnings)
7 errors and 0 warnings potentially fixable with the `--fix` option.
1 change: 0 additions & 1 deletion packages/components/.storybook/addons.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
import '@storybook/addon-actions/register';
import '@storybook/addon-a11y/register';
import 'storybook-addon-i18next/register';
2 changes: 0 additions & 2 deletions packages/components/.storybook/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import '@talend/bootstrap-theme/src/theme/theme.scss';
import React from 'react';

import { configure, addDecorator } from '@storybook/react';
import { withA11y } from '@storybook/addon-a11y';
import { withI18next } from 'storybook-addon-i18next';
import { locales as tuiLocales } from '@talend/locales-tui/locales';

Expand All @@ -20,7 +19,6 @@ addDecorator(
languages,
}),
);
addDecorator(withA11y);

addDecorator(storyFn => (
<>
Expand Down
3 changes: 1 addition & 2 deletions packages/components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"url": "https://github.com/Talend/ui.git"
},
"dependencies": {
"@popperjs/core": "^2.6.0",
"ally.js": "^1.4.1",
"classnames": "^2.2.5",
"d3": "^6.3.0",
Expand All @@ -54,7 +55,6 @@
"react-draggable": "^3.3.0",
"react-grid-layout": "0.16.6",
"react-immutable-proptypes": "^2.1.0",
"react-popper": "^1.3.7",
"react-transition-group": "^2.3.1",
"react-use": "^13.27.0",
"react-virtualized": "9.21.0",
Expand All @@ -67,7 +67,6 @@
"uuid": "^3.4.0"
},
"devDependencies": {
"@storybook/addon-a11y": "^5.3.1",
"@storybook/addon-actions": "^5.3.1",
"@storybook/addons": "^5.3.1",
"@storybook/react": "^5.3.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import PropTypes from 'prop-types';
import omit from 'lodash/omit';
import uuid from 'uuid';
import classnames from 'classnames';
import { Popper } from 'react-popper';

import FocusManager from '../../FocusManager';
import { focusOnCalendar } from '../../Gesture/withCalendarGesture';

import DatePicker from '../Date';
import TimeZone from '../TimeZone';
import useInputPickerHandlers from '../hooks/useInputPickerHandlers';
import { usePopper } from '../../usePopper';

import theme from './InputDatePicker.scss';

Expand Down Expand Up @@ -38,43 +38,29 @@ export default function InputDatePicker(props) {

const inputRef = useRef(null);
const containerRef = useRef(null);

const ref = useRef();
const handlers = useInputPickerHandlers({
handleBlur: props.onBlur,
handleChange: props.onChange,
handleKeyDown: () => focusOnCalendar(containerRef.current),
});
usePopper(inputRef, ref, {
modifiers: [
{ name: 'hide', enabled: false },
{ name: 'preventOverflow', enabled: false },
],
placement: handlers.getPopperPlacement(inputRef.current),
strategy: 'fixed',
});

const inputProps = omit(props, PROPS_TO_OMIT_FOR_INPUT);
const datePicker = [
<DatePicker.Input {...inputProps} id={`${props.id}-input`} key="input" inputRef={inputRef} />,
handlers.showPicker && (
<Popper
key="popper"
modifiers={{
hide: {
enabled: false,
},
preventOverflow: {
enabled: false,
},
}}
placement={handlers.getPopperPlacement(inputRef.current)}
positionFixed
referenceElement={inputRef.current}
>
{({ ref, style }) => (
<div
id={popoverId}
className={theme.popper}
style={style}
ref={ref}
onMouseDown={onMouseDown}
>
<DatePicker.Picker {...props} />
</div>
)}
</Popper>
// eslint-disable-next-line jsx-a11y/no-static-element-interactions
<div id={popoverId} className={theme.popper} ref={ref} onMouseDown={onMouseDown}>
<DatePicker.Picker {...props} />
</div>
),
!props.hideTimezone && props.timezone && <TimeZone key="timezone" timezone={props.timezone} />,
].filter(Boolean);
Expand Down Expand Up @@ -118,4 +104,5 @@ InputDatePicker.propTypes = {
timezone: PropTypes.string,
hideTimezone: PropTypes.bool,
useUTC: PropTypes.bool,
required: PropTypes.bool,
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React, { useRef, useState } from 'react';
import PropTypes from 'prop-types';
import omit from 'lodash/omit';
import classnames from 'classnames';
import { Popper } from 'react-popper';

import FocusManager from '../../FocusManager';
import { focusOnCalendar } from '../../Gesture/withCalendarGesture';
Expand All @@ -14,6 +13,7 @@ import useInputPickerHandlers from '../hooks/useInputPickerHandlers';

import getDefaultT from '../../translate';

import { usePopper } from '../../usePopper';
import theme from './InputDateRangePicker.scss';

const PROPS_TO_OMIT_FOR_INPUT = ['id', 'dateFormat', 'onBlur', 'onChange', 't'];
Expand All @@ -25,6 +25,7 @@ export default function InputDateRangePicker(props) {
const endDateInputRef = useRef(null);
const containerRef = useRef(null);
const [inputRef, setInputRef] = useState(null);
const pickerRef = useRef();

const handlers = useInputPickerHandlers({
handleBlur: props.onBlur,
Expand All @@ -50,6 +51,14 @@ export default function InputDateRangePicker(props) {
}
handlers.onChange(event, payload, inputRef.current);
}
usePopper(inputRef, pickerRef, {
modifiers: [
{ name: 'hide', enabled: false },
{ name: 'preventOverflow', enabled: false },
],
placement: inputRef ? handlers.getPopperPlacement(inputRef.current) : 'bottom-start',
strategy: 'fixed',
});
return (
<DateRange.Manager
startDate={props.startDate}
Expand Down Expand Up @@ -93,26 +102,9 @@ export default function InputDateRangePicker(props) {
ref={endDateInputRef}
/>
{handlers.showPicker && inputRef && (
<Popper
key="popper"
modifiers={{
hide: {
enabled: false,
},
preventOverflow: {
enabled: false,
},
}}
placement={handlers.getPopperPlacement(inputRef.current)}
positionFixed
referenceElement={inputRef.current}
>
{({ ref, style }) => (
<div id={popoverId} className={theme.popper} style={style} ref={ref}>
<DateRange.Picker {...props} focusedInput={getFocusedInput()} />
</div>
)}
</Popper>
<div id={popoverId} className={theme.popper} ref={pickerRef}>
<DateRange.Picker {...props} focusedInput={getFocusedInput()} />
</div>
)}
</FocusManager>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import PropTypes from 'prop-types';
import classnames from 'classnames';
import omit from 'lodash/omit';
import uuid from 'uuid';
import { Popper } from 'react-popper';

import FocusManager from '../../FocusManager';
import Time from '../Time';
Expand All @@ -12,6 +11,7 @@ import TimeZone from '../TimeZone';
import theme from './InputTimePicker.scss';
import useInputPickerHandlers from '../hooks/useInputPickerHandlers';
import focusOnTime from '../gesture/timePickerGesture';
import { usePopper } from '../../usePopper';

const PROPS_TO_OMIT_FOR_INPUT = [
'id',
Expand All @@ -28,42 +28,28 @@ export default function InputTimePicker(props) {

const inputRef = useRef(null);
const containerRef = useRef(null);
const ref = useRef(null);

const handlers = useInputPickerHandlers({
handleBlur: props.onBlur,
handleChange: props.onChange,
handleKeyDown: () => focusOnTime(containerRef.current),
});

usePopper(inputRef, ref, {
modifiers: [
{ name: 'hide', enabled: false },
{ name: 'preventOverflow', enabled: false },
],
placement: inputRef ? handlers.getPopperPlacement(inputRef.current) : 'bottom-start',
strategy: 'fixed',
});
const inputProps = omit(props, PROPS_TO_OMIT_FOR_INPUT);
const timePicker = [
<Time.Input
{...inputProps}
id={`${props.id}-input`}
key="input"
inputRef={inputRef}
/>,
<Time.Input {...inputProps} id={`${props.id}-input`} key="input" inputRef={inputRef} />,
handlers.showPicker && (
<Popper
key="popper"
modifiers={{
hide: {
enabled: false,
},
preventOverflow: {
enabled: false,
},
}}
placement={handlers.getPopperPlacement(inputRef.current)}
positionFixed
referenceElement={inputRef.current}
>
{({ ref, style }) => (
<div id={popoverId} className={theme.popper} style={style} ref={ref}>
<Time.Picker {...props} />
</div>
)}
</Popper>
<div id={popoverId} className={theme.popper} ref={ref}>
<Time.Picker {...props} />
</div>
),
props.timezone && <TimeZone key="timezone" timezone={props.timezone} />,
].filter(Boolean);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import PropTypes from 'prop-types';
import omit from 'lodash/omit';
import keycode from 'keycode';
import uuid from 'uuid';
import { Popper } from 'react-popper';

import FocusManager from '../../../FocusManager';
import { DateTimeContext } from '../DateTime/Context';
import DateTime from '../DateTime';
import { focusOnCalendar } from '../../../Gesture/withCalendarGesture';
import { usePopper } from '../../../usePopper';

import theme from './InputDateTimePicker.scss';

Expand All @@ -30,6 +30,33 @@ function onMouseDown(event) {
event.stopPropagation();
}

function Popper(props) {
const ref = React.useRef();
usePopper(props.inputRef, ref, {
modifiers: [
{ name: 'hide', enabled: false },
{ name: 'preventOverflow', enabled: false },
],
placement: props.getPopperPlacement(),
strategy: 'fixed',
});
return (
<div id={props.popoverId} className={theme.popper} ref={ref} onMouseDown={onMouseDown}>
<DateTime.Picker />
{props.formMode && <DateTime.Validation />}
</div>
);
}
Popper.propTypes = {
formMode: PropTypes.bool.isRequired,
popoverId: PropTypes.string.isRequired,
getPopperPlacement: PropTypes.func.isRequired,
inputRef: PropTypes.oneOfType([
PropTypes.func,
PropTypes.shape({ current: PropTypes.instanceOf(HTMLInputElement) }),
]),
};

class InputDateTimePicker extends React.Component {
static propTypes = {
id: PropTypes.string.isRequired,
Expand Down Expand Up @@ -168,32 +195,12 @@ class InputDateTimePicker extends React.Component {
/>,
this.state.showPicker && (
<Popper
key="popper"
modifiers={{
hide: {
enabled: false,
},
preventOverflow: {
enabled: false,
},
}}
placement={this.getPopperPlacement()}
positionFixed
referenceElement={this.inputRef}
>
{({ ref, style }) => (
<div
id={this.popoverId}
className={theme.popper}
style={style}
ref={ref}
onMouseDown={onMouseDown}
>
<DateTime.Picker />
{this.props.formMode && <DateTime.Validation />}
</div>
)}
</Popper>
inputRef={this.inputRef}
popoverId={this.popoverId}
onMouseDown={this.onMouseDown}
formMode={this.formMode}
getPopperPlacement={this.getPopperPlacement}
/>
),
].filter(Boolean);

Expand Down
Loading