Skip to content

Commit

Permalink
fix: hide unwanted aria messages for date/time pickers
Browse files Browse the repository at this point in the history
  • Loading branch information
simon-hv committed Nov 7, 2023
1 parent 241d90a commit 9d5bdb0
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 34 deletions.
2 changes: 2 additions & 0 deletions packages/DateTimePickerCommon/src/CustomPopper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import styled, { css, CSSObject, th } from '@xstyled/styled-components'
import { cardStyles } from '@welcome-ui/utils'

import { datePickerStyles } from './datePickerStyles'
import { FixAriaMessageStyle } from './styles'

export const CustomPopper = ({
children,
Expand All @@ -21,6 +22,7 @@ export const CustomPopper = ({
const StyledCustomPopper = styled.div(
({ popperStyles }: { popperStyles: CSSObject }) => css`
${datePickerStyles};
${FixAriaMessageStyle};
.react-datepicker-popper {
${popperStyles};
}
Expand Down
2 changes: 1 addition & 1 deletion packages/DateTimePickerCommon/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ export * from './CustomInput'
export * from './utils'

// no export * as S here because of crash on gatsby
export { StyledDatePicker, StyledTimePicker } from './styles'
export { FixGlobalAriaMessage, StyledDatePicker, StyledTimePicker } from './styles'
18 changes: 17 additions & 1 deletion packages/DateTimePickerCommon/src/styles.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import styled, { css, system } from '@xstyled/styled-components'
import styled, { createGlobalStyle, css, system } from '@xstyled/styled-components'
import ReactDatePicker, { ReactDatePickerProps } from 'react-datepicker'
import { StyledIcon } from '@welcome-ui/icon'
import { StyledButton } from '@welcome-ui/button'
Expand Down Expand Up @@ -74,3 +74,19 @@ export const Selects = styled.div`
margin-right: sm;
}
`

export const FixAriaMessageStyle = css`
.react-datepicker__aria-live {
position: absolute;
clip-path: circle(0);
border: 0;
height: 1px;
margin: -1px;
overflow: hidden;
padding: 0;
width: 1px;
white-space: nowrap;
}
`

export const FixGlobalAriaMessage = createGlobalStyle`${FixAriaMessageStyle}`
68 changes: 36 additions & 32 deletions packages/TimePicker/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
CustomInputOptions,
CustomPopper,
DEFAULT_DATE,
FixGlobalAriaMessage,
Focused,
getDate,
StyledTimePicker,
Expand Down Expand Up @@ -97,38 +98,41 @@ export const TimePicker = forwardRef<'input', TimePickerProps>(
}

return (
<StyledTimePicker
calendarClassName="time-picker-popper"
customInput={
<CustomInput
className="time-picker"
data-testid={dataTestId}
focused={focused}
handleBlur={handleBlur}
handleFocus={handleFocus}
icon={icon}
iconPlacement={iconPlacement}
onReset={handleReset}
ref={ref}
size={size}
/>
}
dateFormat={dateFormat}
disabled={disabled}
iconPlacement={!!icon && iconPlacement}
onChange={handleChange}
placeholderText={placeholderText}
popperContainer={CustomPopper}
popperProps={popperProps}
selected={date}
showTimeSelect
showTimeSelectOnly
size={size}
timeIntervals={timeIntervals}
transparent={transparent}
{...rest}
isClearable={false}
/>
<>
<FixGlobalAriaMessage />
<StyledTimePicker
calendarClassName="time-picker-popper"
customInput={
<CustomInput
className="time-picker"
data-testid={dataTestId}
focused={focused}
handleBlur={handleBlur}
handleFocus={handleFocus}
icon={icon}
iconPlacement={iconPlacement}
onReset={handleReset}
ref={ref}
size={size}
/>
}
dateFormat={dateFormat}
disabled={disabled}
iconPlacement={!!icon && iconPlacement}
onChange={handleChange}
placeholderText={placeholderText}
popperContainer={CustomPopper}
popperProps={popperProps}
selected={date}
showTimeSelect
showTimeSelectOnly
size={size}
timeIntervals={timeIntervals}
transparent={transparent}
{...rest}
isClearable={false}
/>
</>
)
}
)
Expand Down

0 comments on commit 9d5bdb0

Please sign in to comment.