Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(DateSelect): Fixes a11y on the Custom option STC-793 #170

Merged
merged 1 commit into from
Dec 29, 2021
Merged
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
13 changes: 9 additions & 4 deletions src/components/Select/SelectOptionCustom.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/** @jsxImportSource theme-ui */
import { useContext, useState } from "react"
import { useContext, useEffect, useState } from "react"

import Button from "../Button/Button"
import Icon from "../Icon/Icon"
Expand Down Expand Up @@ -42,6 +42,14 @@ export const SelectOptionCustom = ({

const isSelected = JSON.stringify(selectedItem) === JSON.stringify(value)

useEffect(() => {
if (highlightedIndex === index) {
setIsOpen(true)
} else {
setIsOpen(false)
}
}, [highlightedIndex, index])

return (
<Popover
isVisible={isOpen}
Expand Down Expand Up @@ -99,9 +107,6 @@ export const SelectOptionCustom = ({
index,
disabled,
})}
onClick={() => {
setIsOpen((value) => !value)
}}
>
<div
sx={{
Expand Down
8 changes: 7 additions & 1 deletion src/components/Select/hooks/useSelect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,19 @@ export function useSelect({
switch (type) {
case useDownshiftSelect.stateChangeTypes.MenuKeyDownEnter:
case useDownshiftSelect.stateChangeTypes.MenuKeyDownSpaceButton:
case useDownshiftSelect.stateChangeTypes.MenuMouseLeave:
case useDownshiftSelect.stateChangeTypes.ItemClick:
const index = options.findIndex(({ value }) => {
return (
JSON.stringify(value) ===
JSON.stringify(changes.selectedItem)
)
})
if (options[index]?.isCustom) return state
if (
options[index]?.isCustom ||
options[state.highlightedIndex]?.isCustom
)
return state
break
}
return changes
Expand Down