Content-Length: 669093 | pFad | http://github.com/saas-js/saas-ui/commit/66d233573c9746dfa50fe5b11cb5a068f445a7f8

6A fix: date range pickers enable input field to trigger dialogue (#191) · saas-js/saas-ui@66d2335 · GitHub
Skip to content

Commit

Permalink
fix: date range pickers enable input field to trigger dialogue (#191)
Browse files Browse the repository at this point in the history
* chore: remove unused var

* fix: date picker fixes

* fix: use correct hook
  • Loading branch information
Pagebakers authored Jan 12, 2024
1 parent 829a336 commit 66d2335
Show file tree
Hide file tree
Showing 15 changed files with 231 additions and 107 deletions.
5 changes: 5 additions & 0 deletions .changeset/hip-panthers-unite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@saas-ui/date-picker': patch
---

Improved DatePicker to enable keyboard navigation on calendar days after opening
5 changes: 5 additions & 0 deletions .changeset/khaki-bears-obey.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@saas-ui/date-picker': patch
---

Fixed issue where date picker dialog would not open using keyboard controls
20 changes: 10 additions & 10 deletions apps/website/public/blog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@
<category>nextjs</category><category>react</category><category>next app router</category><category>saas ui</category><category>dashboard</category><category>app development</category>
</item>

<item>
<guid>https://saas-ui.dev/blog/introducing-charts-for-chakra-ui</guid>
<title>Introducing 4 new Open Source data visualization components for Chakra UI.</title>
<link>https://saas-ui.dev/blog/introducing-charts-for-chakra-ui</link>
<description>Build beautiful metrics dashboards faster with Area, Bar, Line and Sparkline charts for Chakra UI.</description>
<pubDate>Fri, 12 Jan 2024 00:00:00 GMT</pubDate>
<author>hello@saas-ui.dev (Eelco Wiersma)</author>

</item>

<item>
<guid>https://saas-ui.dev/blog/introducing-glass-theme-for-chakra-ui</guid>
<title>Introducing the new Glass theme for Chakra UI</title>
Expand Down Expand Up @@ -68,16 +78,6 @@
<pubDate>Fri, 24 Nov 2023 00:00:00 GMT</pubDate>
<author>hello@saas-ui.dev (Eelco Wiersma)</author>

</item>

<item>
<guid>https://saas-ui.dev/blog/introducing-charts-for-chakra-ui</guid>
<title>Introducing 4 new Open Source data visualization components for Chakra UI.</title>
<link>https://saas-ui.dev/blog/introducing-charts-for-chakra-ui</link>
<description>Build beautiful metrics dashboards faster with Area, Bar, Line and Sparkline charts for Chakra UI.</description>
<pubDate>Fri, 12 Jan 2024 00:00:00 GMT</pubDate>
<author>hello@saas-ui.dev (Eelco Wiersma)</author>

</item>

</channel>
Expand Down
2 changes: 1 addition & 1 deletion packages/pro
Submodule pro updated from 4cbd13 to 4cd634
1 change: 0 additions & 1 deletion packages/saas-ui-charts/src/area-chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ export const AreaChart = React.forwardRef<HTMLDivElement, AreaChartProps>(
yAxisWidth = 40,
legendHeight = 32,
animationDuration = 500,
name,
valueFormatter,
variant = 'gradient',
tooltipContent,
Expand Down
1 change: 1 addition & 0 deletions packages/saas-ui-date-picker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"@react-aria/calendar": "^3.5.3",
"@react-aria/datepicker": "^3.9.0",
"@react-aria/i18n": "^3.9.0",
"@react-aria/interactions": "^3.20.1",
"@react-stately/calendar": "^3.4.2",
"@react-stately/datepicker": "^3.9.0",
"@saas-ui/core": "workspace:*",
Expand Down
67 changes: 36 additions & 31 deletions packages/saas-ui-date-picker/src/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
IconButtonProps,
} from '@chakra-ui/react'
import { callAllHandlers } from '@chakra-ui/utils'
import { Pressable } from '@react-aria/interactions'

interface FieldButtonProps extends ButtonProps {
onPress?(e: any): void
Expand All @@ -15,25 +16,26 @@ interface FieldButtonProps extends ButtonProps {

export const FieldButton = forwardRef<FieldButtonProps, 'button'>(
(props, ref) => {
const { onPress: onClick, onFocusChange, onFocus, onBlur, ...rest } = props
const { onPress, onFocusChange, onFocus, onBlur, ...rest } = props

return (
<Button
ref={ref}
size="sm"
h="1.75rem"
mr="2"
onClick={onClick}
onFocus={() =>
callAllHandlers(() => onFocusChange?.(true), props.onFocus)
}
onBlur={() =>
callAllHandlers(() => onFocusChange?.(false), props.onBlur)
}
{...rest}
>
{props.children}
</Button>
<Pressable onPress={onPress}>
<Button
ref={ref}
size="sm"
h="1.75rem"
mr="2"
onFocus={() =>
callAllHandlers(() => onFocusChange?.(true), props.onFocus)
}
onBlur={() =>
callAllHandlers(() => onFocusChange?.(false), props.onBlur)
}
{...rest}
>
{props.children}
</Button>
</Pressable>
)
}
)
Expand All @@ -44,21 +46,24 @@ export interface NavButtonProps extends IconButtonProps {
}

export const NavButton = forwardRef<NavButtonProps, 'button'>((props, ref) => {
const { onPress: onClick, onFocusChange, onFocus, onBlur, ...rest } = props
const { onPress, onFocusChange, onFocus, onBlur, ...rest } = props

return (
<IconButton
ref={ref}
size="sm"
variant="ghost"
onClick={onClick}
onFocus={() =>
callAllHandlers(() => onFocusChange?.(true), props.onFocus)
}
onBlur={() => callAllHandlers(() => onFocusChange?.(false), props.onBlur)}
{...rest}
>
{props.children}
</IconButton>
<Pressable onPress={onPress}>
<IconButton
ref={ref}
size="sm"
variant="ghost"
onFocus={() =>
callAllHandlers(() => onFocusChange?.(true), props.onFocus)
}
onBlur={() =>
callAllHandlers(() => onFocusChange?.(false), props.onBlur)
}
{...rest}
>
{props.children}
</IconButton>
</Pressable>
)
})
57 changes: 43 additions & 14 deletions packages/saas-ui-date-picker/src/date-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,20 @@ import {
InputRightElement,
Portal,
SystemCSSProperties,
useMergeRefs,
usePopoverContext,
} from '@chakra-ui/react'

import { FieldButton } from './button'
import { DatePickerCalendar } from './calendar'
import { DateField, DatePickerTimeField } from './date-field'
import { DatePickerDialog, DatePickerTrigger } from './date-picker-dialog'
import {
DatePickerAnchor,
DatePickerDialog,
DatePickerDialogProps,
} from './date-picker-dialog'
import { DatePicker, DatePickerProps } from './date-picker'
import { useDatePickerContext } from './date-picker-context'
import { useDatePickerContext, useDatePickerInput } from './date-picker-context'
import { SegmentedInput } from './segmented-input'
import { CalendarIcon } from './icons'

Expand All @@ -28,6 +34,14 @@ export interface DateInputProps extends DatePickerProps {
* Also accepts a `z-index` value that will be passed to the dialog.
*/
portal?: boolean | SystemCSSProperties['zIndex']
/**
* The DatePickerInput props.
*/
inputProps?: DatePickerInputProps
/**
* The DatePickerDialog props.
*/
dialogProps?: DatePickerDialogProps
}

/**
Expand All @@ -36,12 +50,21 @@ export interface DateInputProps extends DatePickerProps {
* @see Docs https://saas-ui.dev/docs/date-time/date-picker-input
*/
export const DateInput = forwardRef<DateInputProps, 'div'>((props, ref) => {
const { children, calendarIcon, size, variant, portal, ...rest } = props
const {
children,
calendarIcon,
size,
variant,
inputProps,
dialogProps,
portal,
...rest
} = props

const zIndex = typeof portal === 'boolean' ? undefined : portal

const dialog = (
<DatePickerDialog zIndex={zIndex}>
<DatePickerDialog zIndex={zIndex} {...dialogProps}>
<>
<DatePickerCalendar />
{children}
Expand All @@ -56,6 +79,7 @@ export const DateInput = forwardRef<DateInputProps, 'div'>((props, ref) => {
size={size}
variant={variant}
ref={ref}
{...inputProps}
/>

{portal ? <Portal>{dialog}</Portal> : dialog}
Expand Down Expand Up @@ -107,17 +131,22 @@ export const DatePickerInput = forwardRef<DatePickerInputProps, 'div'>(
fieldProps,
buttonProps,
datePickerRef,
} = useDatePickerContext()
} = useDatePickerInput()

const themeProps = { size, variant }

return (
<InputGroup {...rest} {...groupProps} {...themeProps} ref={datePickerRef}>
<SegmentedInput {...themeProps}>
<DateField locale={locale} {...fieldProps} ref={ref} />
</SegmentedInput>
<InputRightElement py="1">
<DatePickerTrigger>
<DatePickerAnchor>
<InputGroup
ref={datePickerRef}
{...rest}
{...groupProps}
{...themeProps}
>
<SegmentedInput {...themeProps}>
<DateField ref={ref} locale={locale} {...fieldProps} />
</SegmentedInput>
<InputRightElement py="1">
<FieldButton
variant="ghost"
flex="1"
Expand All @@ -127,9 +156,9 @@ export const DatePickerInput = forwardRef<DatePickerInputProps, 'div'>(
>
{calendarIcon || <CalendarIcon />}
</FieldButton>
</DatePickerTrigger>
</InputRightElement>
</InputGroup>
</InputRightElement>
</InputGroup>
</DatePickerAnchor>
)
}
)
Expand Down
75 changes: 71 additions & 4 deletions packages/saas-ui-date-picker/src/date-picker-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
now,
} from '@internationalized/date'
import { isDateInRange } from './date-utils'
import { usePopoverContext } from '@chakra-ui/react'

export const [DatePickerStylesProvider, useDatePickerStyles] = createContext<
Record<string, SystemStyleObject>
Expand Down Expand Up @@ -77,8 +78,76 @@ export const useDateRangePickerContext = () => {
}

export const useDatePickerDialog = () => {
const { dialogProps } = useContext()
return { dialogProps }
const { dialogProps, state, datePickerRef } = useContext()

React.useEffect(() => {
if (state.isOpen) {
setTimeout(() => {
const parent = datePickerRef.current?.parentNode
const el =
parent?.querySelector<HTMLElement>('[data-selected]') ||
parent?.querySelector<HTMLElement>('[data-today]') ||
parent?.querySelector<HTMLElement>(
'td button:not([aria-disabled="true"])'
)

el?.focus()
}, 0)
}
}, [datePickerRef, state.isOpen])

return {
dialogProps: {
...dialogProps,
},
}
}

export const useDatePickerInput = () => {
const popover = usePopoverContext()
const { onClick, ...triggerProps } = popover.getTriggerProps()

const context = useDatePickerContext()

const { state, locale, groupProps, datePickerRef } = context

const buttonProps = {
...context.buttonProps,
...triggerProps,
}

return {
fieldProps: context.fieldProps,
groupProps,
buttonProps,
datePickerRef,
locale,
state,
}
}

export const useDateRangePickerInput = () => {
const popover = usePopoverContext()
const { onClick, ...triggerProps } = popover.getTriggerProps()

const context = useDateRangePickerContext()

const { state, locale, groupProps, datePickerRef } = context

const buttonProps = {
...context.buttonProps,
...triggerProps,
}

return {
groupProps,
buttonProps,
datePickerRef,
locale,
state,
startFieldProps: context.startFieldProps,
endFieldProps: context.endFieldProps,
}
}

export interface UseCalenderCellProps extends AriaCalendarCellProps {
Expand All @@ -99,8 +168,6 @@ export const useCalendarCell = (
isSelected,
isInvalid,
formattedDate,
isDisabled,
isFocused,
isOutsideVisibleRange,
isUnavailable,
} = useAriaCalendarCell({ date }, state, ref)
Expand Down
2 changes: 1 addition & 1 deletion packages/saas-ui-date-picker/src/date-picker-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export interface DatePickerDialogProps
}

export const DatePickerDialog: React.FC<DatePickerDialogProps> = (props) => {
const { children, hideArrow, ...rest } = props
const { children, hideArrow = true, ...rest } = props

const { dialogProps } = useDatePickerDialog()
const styles = useDatePickerStyles()
Expand Down
Loading

1 comment on commit 66d2335

@vercel
Copy link

@vercel vercel bot commented on 66d2335 Jan 12, 2024

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.








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/saas-js/saas-ui/commit/66d233573c9746dfa50fe5b11cb5a068f445a7f8

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy