Skip to content

Commit

Permalink
fix: scrolling long panels (#401)
Browse files Browse the repository at this point in the history
  • Loading branch information
RodrigoHamuy authored Oct 28, 2022
1 parent 6196c2c commit 8b21a5c
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .changeset/grumpy-horses-wash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'leva': patch
'@leva-ui/plugin-dates': patch
---

fix: scrolling long panels
2 changes: 1 addition & 1 deletion packages/leva/src/components/Folder/StyledFolder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const StyledWrapper = styled('div', {
fill: false,
css: {
// TODO: fix for calendar popup
// overflowY: 'auto',
overflowY: 'auto',
// 20px accounts for top margin
maxHeight: 'calc(100vh - 20px - $$titleBarHeight)',
},
Expand Down
11 changes: 11 additions & 0 deletions packages/leva/stories/panel-options.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,14 @@ export const NeverHide: Story<any> = () => {
</div>
)
}

export const ReallyLongPanel = () => {
useControls({
...Object.fromEntries(
Array(50)
.fill(0)
.map((_, i) => [i, i])
),
})
return <></>
}
15 changes: 15 additions & 0 deletions packages/plugin-dates/src/Date.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,18 @@ CustomLocale.args = { date: new Date(), locale: 'en-US' }

export const CustomInputFormat = Template.bind({})
CustomInputFormat.args = { date: new Date(), inputFormat: 'yyyy-MM-dd' }

export const WithOtherFields = () => {
const { birthday, ...values } = useControls({
text: 'text',
birthday: date({ date: new Date() }),
number: 0,
})
return (
<div>
{birthday.formattedDate}
<br />
{JSON.stringify(values)}
</div>
)
}
8 changes: 6 additions & 2 deletions packages/plugin-dates/src/Date.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Components, useInputContext } from 'leva/plugin'
import React, { forwardRef } from 'react'
import React, { forwardRef, useState } from 'react'
import DatePicker, { CalendarContainer } from 'react-datepicker'
import 'react-datepicker/dist/react-datepicker.css'
import { DateCalendarContainerProps, DateInputProps, DateProps } from './date-types'
Expand All @@ -22,8 +22,10 @@ const DateInput = forwardRef<HTMLInputElement, Partial<DateInputProps>>(({ value
export function Date() {
const { label, value, onUpdate, settings } = useInputContext<DateProps>()

const [isOpen, setIsOpen] = useState(false)

return (
<Row input>
<Row input style={{ height: isOpen ? 300 : 'auto' }}>
<Label>{label}</Label>
<InputContainer>
<DatePicker
Expand All @@ -32,6 +34,8 @@ export function Date() {
dateFormat={settings.inputFormat}
calendarContainer={DateCalendarContainer}
customInput={<DateInput />}
onCalendarOpen={() => setIsOpen(true)}
onCalendarClose={() => setIsOpen(false)}
/>
</InputContainer>
</Row>
Expand Down

1 comment on commit 8b21a5c

@vercel
Copy link

@vercel vercel bot commented on 8b21a5c Oct 28, 2022

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

leva – ./

leva-git-main-pmndrs.vercel.app
leva.pmnd.rs
leva-pmndrs.vercel.app
leva.vercel.app

Please sign in to comment.