Skip to content

Commit

Permalink
fix: double click on datepicker popper to select date (#408)
Browse files Browse the repository at this point in the history
* disable autocomplete

https://trello.com/c/ZoHydMQR/167-datetimepicker-issue
Signed-off-by: Paul-Xavier Ceccaldi <[email protected]>
  • Loading branch information
P1X3L authored Oct 24, 2019
1 parent 3951c24 commit 2ad9475
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 17 deletions.
22 changes: 14 additions & 8 deletions src/components/Alert/doc.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,38 @@ Simple feedback messages for user actions.
<Box>
<Alert>
<AlertTitle>Error variant</AlertTitle>
<span>Nunc laoreet egestas nulla, et dapibus sem malesuada in. Suspendisse eleifend accumsan ultrices. Phasellus iaculis nisi sed dui ornare commodo. Nullam dapibus varius nibh a ornare.</span>
<span>
Nunc laoreet egestas nulla, et dapibus sem malesuada in. Suspendisse eleifend accumsan ultrices. Phasellus iaculis nisi sed dui ornare commodo. Nullam dapibus varius nibh a ornare.
</span>
</Alert>
</Box>

<Box mt="xl">
<Alert variant="warning">
<AlertTitle>Warning variant</AlertTitle>
<span>Nunc laoreet egestas nulla, et dapibus sem malesuada in.
Suspendisse eleifend accumsan ultrices. Phasellus iaculis nisi sed dui ornare commodo. Nullam
dapibus varius nibh a ornare.</span>
<span>
Nunc laoreet egestas nulla, et dapibus sem malesuada in. Suspendisse eleifend accumsan
ultrices. Phasellus iaculis nisi sed dui ornare commodo. Nullam dapibus varius nibh a ornare.
</span>
</Alert>
</Box>

<Box mt="xl">
<Alert variant="success">
<AlertTitle>Success variant</AlertTitle>
<span>Nunc laoreet egestas nulla, et dapibus sem malesuada in.
Suspendisse eleifend accumsan ultrices. Phasellus iaculis nisi sed dui ornare commodo. Nullam
dapibus varius nibh a ornare.</span>
<span>
Nunc laoreet egestas nulla, et dapibus sem malesuada in. Suspendisse eleifend accumsan
ultrices. Phasellus iaculis nisi sed dui ornare commodo. Nullam dapibus varius nibh a ornare.
</span>
</Alert>
</Box>

<Box mt="xl">
<Alert variant="info">
<AlertTitle>Info variant</AlertTitle>
<span>Nunc laoreet egestas nulla, et dapibus sem malesuada in. Suspendisse eleifend accumsan ultrices. Phasellus iaculis nisi sed dui ornare commodo. Nullam dapibus varius nibh a ornare.</span>
<span>
Nunc laoreet egestas nulla, et dapibus sem malesuada in. Suspendisse eleifend accumsan ultrices. Phasellus iaculis nisi sed dui ornare commodo. Nullam dapibus varius nibh a ornare.
</span>
</Alert>
</Box>
</Playground>
Expand Down
17 changes: 15 additions & 2 deletions src/components/DatePicker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export const DatePicker = forwardRef(

const [focused, setFocused] = useState((autoFocus && 'date') || null)
const [date, setDate] = useState(formatDate(value))
const inputReference = inputRef || ref

// format date at component mount
useEffect(() => {
Expand All @@ -56,6 +57,8 @@ export const DatePicker = forwardRef(
//eslint-disable-next-line
}, [value])

const blur = () => inputReference.current.blur()

const handleFocus = e => {
setFocused('date')
onFocus && onFocus(e)
Expand All @@ -66,8 +69,15 @@ export const DatePicker = forwardRef(
onBlur && onBlur(e)
}

const handleKeyDown = e => {
if (e.key === 'Escape') {
blur()
}
}

const handleReset = e => {
e.preventDefault()
blur()
setDate(null)
onChange && onChange()
}
Expand All @@ -83,6 +93,7 @@ export const DatePicker = forwardRef(

return (
<S.DatePicker
autoComplete="off"
calendarClassName="date-picker-popper"
customInput={
<CustomInput
Expand All @@ -93,16 +104,18 @@ export const DatePicker = forwardRef(
handleFocus={e => handleFocus('date', e)}
icon={icon}
iconPlacement={iconPlacement}
inputRef={inputRef || ref}
inputRef={inputReference}
onReset={handleReset}
size={size}
/>
}
dateFormat={dateFormat}
locale={locale}
onChange={handleChange}
onKeyDown={handleKeyDown}
placeholderText={placeholderText}
popperContainer={props => DatePickerPopper({ popperZIndex, ...props })}
popperContainer={DatePickerPopper}
popperProps={{ zIndex: popperZIndex }}
renderCustomHeader={props => (
<CustomHeader endYear={endYear} locale={locale} startYear={startYear} {...props} />
)}
Expand Down
9 changes: 6 additions & 3 deletions src/components/DatePickerPopper/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ import { createPortal } from 'react-dom'

import * as S from './styles'

export const DatePickerPopper = ({ children, popperZIndex }) =>
typeof window !== 'undefined'
export const DatePickerPopper = props => {
const { children } = props
if (!children) return null
return typeof window !== 'undefined'
? createPortal(
<S.Popper zIndex={popperZIndex}>{children}</S.Popper>,
<S.Popper {...children.props}>{children}</S.Popper>,
document.querySelector('body')
)
: null
}
2 changes: 1 addition & 1 deletion src/components/DateTimePicker/CustomInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class CustomInput extends PureComponent {
{icon}
</IconWrapper>
)}
<input autoComplete="new-password" ref={inputRef} value={value} {...rest} />
<input ref={inputRef} value={value} {...rest} />
{value && (
<IconWrapper iconPlacement="right" size={size}>
<ClearButton aria-label="clear date" onClick={onReset} />
Expand Down
8 changes: 5 additions & 3 deletions src/components/Link/doc.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ Can be `primary` by default or `secondary`
It can also be `disabled`

<Playground>
<Link disabled href="#">primary link</Link>
<Link disabled href="#">
primary link
</Link>
</Playground>

## Special case
Expand All @@ -42,10 +44,10 @@ Use `<Text>` with `underline` props to add specific style _(here a border line)_
<Playground>
<Box>
<Link as={LinkDocz} to="/components/shape" variant="secondary">
<Shape width="30px" height="30px" shape="circle">
<Shape height="30px" shape="circle" width="30px">
<img src="https://avatars3.githubusercontent.com/u/13100706?s=200&v=4" />
</Shape>
<Text as="span" variant="body2" underline>
<Text as="span" underline variant="body2">
see shape component
</Text>
</Link>
Expand Down
1 change: 1 addition & 0 deletions src/utils/reservedProps.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ const customProps = [
'isSearchable',
'maxSize',
'minRows',
'popperZIndex',
'renderItem'
]

Expand Down

1 comment on commit 2ad9475

@vercel
Copy link

@vercel vercel bot commented on 2ad9475 Oct 24, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.