1- import React , { useState , useRef , useEffect } from "react" ;
1+ import React , { useState , useRef , useEffect , useId } from "react" ;
22import styled , { css } from "styled-components" ;
33import { landscapeStyle } from "styles/landscapeStyle" ;
44
@@ -63,7 +63,7 @@ const ChevronIcon = styled.span<{ isOpen: boolean }>`
6363 margin-top: -4px;
6464` ;
6565
66- const DropdownContainer = styled . div < { isOpen : boolean ; isMobileNavbar ?: boolean } > `
66+ const DropdownContainer = styled . div < { isOpen : boolean } > `
6767 position: absolute;
6868 top: 100%;
6969 left: 0;
@@ -183,6 +183,7 @@ const Policies: React.FC<IPolicies> = ({ isMobileNavbar }) => {
183183 const [ isOpen , setIsOpen ] = useState ( false ) ;
184184 const dropdownRef = useRef < HTMLDivElement > ( null ) ;
185185 const { toggleIsOpen } = useOpenContext ( ) ;
186+ const menuId = useId ( ) ;
186187
187188 // Policy documents configuration
188189
@@ -214,12 +215,12 @@ const Policies: React.FC<IPolicies> = ({ isMobileNavbar }) => {
214215 } ;
215216 } , [ ] ) ;
216217
217- const handleItemClick = ( policy : typeof policies [ 0 ] ) => {
218+ const handleItemClick = ( ) => {
218219 setIsOpen ( false ) ;
219220 if ( isMobileNavbar ) {
220221 toggleIsOpen ( ) ;
221222 }
222- window . open ( policy . url , "_blank" ) ;
223+ // Let the anchor's default behavior open the link in a new tab (with rel attr).
223224 } ;
224225
225226 const handleToggleDropdown = ( ) => {
@@ -230,15 +231,19 @@ const Policies: React.FC<IPolicies> = ({ isMobileNavbar }) => {
230231 < Container ref = { dropdownRef } >
231232 < Title > Policies</ Title >
232233 < PoliciesButton
234+ type = "button"
233235 onClick = { handleToggleDropdown }
234236 isActive = { isOpen }
235237 isMobileNavbar = { isMobileNavbar }
238+ aria-haspopup = "menu"
239+ aria-expanded = { isOpen }
240+ aria-controls = { menuId }
236241 >
237242 Policies
238243 < ChevronIcon isOpen = { isOpen } />
239244 </ PoliciesButton >
240245
241- < DropdownContainer isOpen = { isOpen } isMobileNavbar = { isMobileNavbar } >
246+ < DropdownContainer id = { menuId } role = "menu" isOpen = { isOpen } >
242247 { policies . map ( ( policy ) => {
243248 const IconComponent = policy . icon ;
244249 return (
@@ -247,10 +252,8 @@ const Policies: React.FC<IPolicies> = ({ isMobileNavbar }) => {
247252 href = { policy . url }
248253 target = "_blank"
249254 rel = "noopener noreferrer"
250- onClick = { ( e ) => {
251- e . preventDefault ( ) ;
252- handleItemClick ( policy ) ;
253- } }
255+ onClick = { handleItemClick }
256+ role = "menuitem"
254257 >
255258 < ItemIcon >
256259 < IconComponent />
0 commit comments