diff --git a/src/app/components/Dropdown.tsx b/src/app/components/Dropdown.tsx index a2f009e0f7..de52e7a683 100644 --- a/src/app/components/Dropdown.tsx +++ b/src/app/components/Dropdown.tsx @@ -1,3 +1,4 @@ + import { HTMLElement } from '@openstax/types/lib.dom'; import flow from 'lodash/fp/flow'; import isUndefined from 'lodash/fp/isUndefined'; @@ -5,9 +6,9 @@ import omitBy from 'lodash/fp/omitBy'; import React, { ReactNode } from 'react'; import { FormattedMessage, useIntl } from 'react-intl'; import styled, { css, keyframes } from 'styled-components/macro'; -import { useFocusLost } from '../reactUtils'; +import { useFocusLost, useTrapTabNavigation } from '../reactUtils'; import { useOnEsc } from '../reactUtils'; -import theme from '../theme'; +import theme, { defaultFocusOutline } from '../theme'; import { preventDefault } from '../utils'; import { textStyle } from './Typography/base'; @@ -165,8 +166,19 @@ const TabTransparentDropdown = styled(( `} `; +function TrappingDropdownList(props: object) { + const ref = React.useRef(null); + + useTrapTabNavigation(ref); + + return ( +
    + ); +} + + // tslint:disable-next-line:variable-name -export const DropdownList = styled.ol` +export const DropdownList = styled(TrappingDropdownList)` margin: 0; padding: 0.6rem 0; background: ${theme.color.neutral.formBackground}; @@ -198,12 +210,12 @@ export const DropdownList = styled.ol` &:hover, &:focus { background: ${theme.color.neutral.formBorder}; - outline: 0.2rem auto Highlight; - outline: 0.2rem inset -webkit-focus-ring-color; + ${defaultFocusOutline} } } `; + interface DropdownItemProps { message: string; ariaMessage?: string; diff --git a/src/app/components/__snapshots__/DotMenu.spec.tsx.snap b/src/app/components/__snapshots__/DotMenu.spec.tsx.snap index 80acb6703f..b3fb1c0479 100644 --- a/src/app/components/__snapshots__/DotMenu.spec.tsx.snap +++ b/src/app/components/__snapshots__/DotMenu.spec.tsx.snap @@ -179,7 +179,7 @@ exports[`Dropdown matches snapshot 1`] = ` .c12 li a:focus { background: #d5d5d5; outline: 0.2rem auto Highlight; - outline: 0.2rem inset -webkit-focus-ring-color; + outline: 0.2rem auto -webkit-focus-ring-color; } .c12.c12 { @@ -452,7 +452,7 @@ exports[`Dropdown matches snapshot on right align 1`] = ` .c12 li a:focus { background: #d5d5d5; outline: 0.2rem auto Highlight; - outline: 0.2rem inset -webkit-focus-ring-color; + outline: 0.2rem auto -webkit-focus-ring-color; } .c12.c12 { @@ -499,6 +499,7 @@ exports[`Dropdown matches snapshot on right align 1`] = `