Skip to content

Commit 757edef

Browse files
fix(PDYE-1342): respuesta a presionar enter (#740)
Co-authored-by: Javiera Munita <javiera.munita@eclass.cl>
1 parent d28268c commit 757edef

File tree

3 files changed

+43
-4
lines changed

3 files changed

+43
-4
lines changed

src/organisms/Calendar/Dropdown/CalendarDropdown/Components/GoToCalendar.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export const GoToCalendar = ({ text, onlyToCalendar, onClick }: IGoToCalendar):
1515

1616
return (
1717
<MenuButton
18+
tabIndex={-1}
1819
onClick={() => onlyToCalendar && onClick && onClick()}
1920
position="relative"
2021
sx={{

src/organisms/CourseList/Boxes/BoxTraditional.tsx

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { Ripples } from '@atoms'
66
import { vars } from '@theme'
77
import { isCourseActive } from '../utils'
88
import * as Type from '../types'
9+
import { useEnterNavigate } from '../utils/useEnterNavigate'
910

1011
export const CourseBoxContext = React.createContext<Partial<Type.ExtendAcademicList>>({})
1112

@@ -25,6 +26,8 @@ export function BoxTraditional({ data, modalPaymentText }: IBoxTraditional): JSX
2526
const isClickable = isCourseActive(data.action?.enabled ?? false, data.Profile?.id)
2627
const hasHref = !!data.action?.href
2728

29+
useEnterNavigate()
30+
2831
const cssActive = {
2932
boxShadow: `0 2px 7px 0 ${vars('colors-neutral-silverSand')}`,
3033
}
@@ -33,6 +36,7 @@ export function BoxTraditional({ data, modalPaymentText }: IBoxTraditional): JSX
3336
<CourseBoxContext.Provider value={data}>
3437
<LinkBox
3538
as="article"
39+
className="focusable-link"
3640
border={vars('borders-light')}
3741
borderRadius={vars('radii-big')}
3842
cursor={isClickable ? 'pointer' : 'default'}
@@ -43,14 +47,21 @@ export function BoxTraditional({ data, modalPaymentText }: IBoxTraditional): JSX
4347
_focusWithin={{
4448
boxShadow: `0 0 0 3px ${vars('colors-alert-deepSkyBlue')} inset`,
4549
}}
46-
tabIndex={!hasHref && isClickable ? 0 : undefined}
47-
role="link"
50+
tabIndex={0}
51+
role={hasHref ? 'link' : undefined}
52+
data-href={hasHref ? data.action?.href : undefined}
4853
>
49-
<WithRipples enabled={isCourseActive(data.action?.enabled ?? false, data.Profile?.id)}>
54+
<WithRipples enabled={isClickable}>
5055
<Flex direction="column" justify="space-between" h="100%">
5156
<Box className="CourseList-TraditionalBox">
5257
{isClickable && hasHref && (
53-
<LinkOverlay href={data.action?.href} isExternal={data.action?.targetBlank} />
58+
<LinkOverlay
59+
className="course-link-overlay"
60+
bg="gray"
61+
href={data.action?.href}
62+
isExternal={data.action?.targetBlank}
63+
tabIndex={-1}
64+
/>
5465
)}
5566
<Header />
5667
<Section />
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/* eslint-disable */
2+
import { useEffect } from 'react'
3+
4+
export function useEnterNavigate(): void {
5+
useEffect(() => {
6+
const handleKeyDown = (e: KeyboardEvent): void => {
7+
if (e.key === 'Enter') {
8+
const active = document.activeElement as HTMLElement | null
9+
const role = active?.getAttribute('role')
10+
const href = active?.getAttribute('data-href')
11+
12+
const isFocusableLink =
13+
active?.classList?.contains('chakra-linkbox') ||
14+
active?.classList?.contains('focusable-link')
15+
16+
if (role === 'link' && href != null && isFocusableLink) {
17+
window.location.href = href
18+
}
19+
}
20+
}
21+
22+
window.addEventListener('keydown', handleKeyDown)
23+
return () => {
24+
window.removeEventListener('keydown', handleKeyDown)
25+
}
26+
}, [])
27+
}

0 commit comments

Comments
 (0)