1
- import React , { useState , useRef , useEffect , useId } from "react" ;
1
+ import React , { useState , useRef , useEffect } from "react" ;
2
2
import styled , { css } from "styled-components" ;
3
3
import { landscapeStyle } from "styles/landscapeStyle" ;
4
+ import { hoverShortTransitionTiming } from "styles/commonStyles" ;
4
5
5
6
import { useOpenContext } from "../MobileHeader" ;
6
7
@@ -28,6 +29,7 @@ const Title = styled.h1`
28
29
` ;
29
30
30
31
const PoliciesButton = styled . button < { isActive : boolean ; isMobileNavbar ?: boolean } > `
32
+ ${ hoverShortTransitionTiming }
31
33
display: flex;
32
34
align-items: center;
33
35
gap: 8px;
@@ -46,10 +48,13 @@ const PoliciesButton = styled.button<{ isActive: boolean; isMobileNavbar?: boole
46
48
47
49
${ landscapeStyle (
48
50
( ) => css `
49
- color: ${ ( { theme } ) => theme . white } ;
50
51
padding: 16px 8px;
51
52
`
52
- ) } ;
53
+ ) }
54
+
55
+ @media (min-width: 900px) {
56
+ color: ${ ( { isActive, theme } ) => ( isActive ? theme . white : `${ theme . white } BA` ) } ;
57
+ }
53
58
` ;
54
59
55
60
const ChevronIcon = styled . span < { isOpen : boolean } > `
@@ -175,17 +180,13 @@ const DocumentIcon = styled.div`
175
180
` ;
176
181
177
182
interface IPolicies {
178
- /** Whether the component is being used in the mobile navbar */
179
183
isMobileNavbar ?: boolean ;
180
184
}
181
185
182
186
const Policies : React . FC < IPolicies > = ( { isMobileNavbar } ) => {
183
187
const [ isOpen , setIsOpen ] = useState ( false ) ;
184
188
const dropdownRef = useRef < HTMLDivElement > ( null ) ;
185
189
const { toggleIsOpen } = useOpenContext ( ) ;
186
- const menuId = useId ( ) ;
187
-
188
- // Policy documents configuration
189
190
190
191
const policies = [
191
192
{
@@ -210,40 +211,32 @@ const Policies: React.FC<IPolicies> = ({ isMobileNavbar }) => {
210
211
} ;
211
212
212
213
document . addEventListener ( "mousedown" , handleClickOutside ) ;
213
- return ( ) => {
214
- document . removeEventListener ( "mousedown" , handleClickOutside ) ;
215
- } ;
214
+ return ( ) => document . removeEventListener ( "mousedown" , handleClickOutside ) ;
216
215
} , [ ] ) ;
217
216
218
217
const handleItemClick = ( ) => {
219
218
setIsOpen ( false ) ;
220
219
if ( isMobileNavbar ) {
221
220
toggleIsOpen ( ) ;
222
221
}
223
- // Let the anchor's default behavior open the link in a new tab (with rel attr).
224
- } ;
225
-
226
- const handleToggleDropdown = ( ) => {
227
- setIsOpen ( ! isOpen ) ;
228
222
} ;
229
223
230
224
return (
231
225
< Container ref = { dropdownRef } >
232
226
< Title > Policies</ Title >
233
227
< PoliciesButton
234
228
type = "button"
235
- onClick = { handleToggleDropdown }
229
+ onClick = { ( ) => setIsOpen ( ! isOpen ) }
236
230
isActive = { isOpen }
237
231
isMobileNavbar = { isMobileNavbar }
238
232
aria-haspopup = "menu"
239
233
aria-expanded = { isOpen }
240
- aria-controls = { menuId }
241
234
>
242
235
Policies
243
236
< ChevronIcon isOpen = { isOpen } />
244
237
</ PoliciesButton >
245
238
246
- < DropdownContainer id = { menuId } role = "menu" isOpen = { isOpen } >
239
+ < DropdownContainer isOpen = { isOpen } >
247
240
{ policies . map ( ( policy ) => {
248
241
const IconComponent = policy . icon ;
249
242
return (
@@ -253,7 +246,6 @@ const Policies: React.FC<IPolicies> = ({ isMobileNavbar }) => {
253
246
target = "_blank"
254
247
rel = "noopener noreferrer"
255
248
onClick = { handleItemClick }
256
- role = "menuitem"
257
249
>
258
250
< ItemIcon >
259
251
< IconComponent />
0 commit comments