-
Notifications
You must be signed in to change notification settings - Fork 10.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Skip to main content shortcut and
useDocumentTitle
(#30680)
Co-authored-by: Guilherme Gazzo <guilhermegazzo@gmail.com>
- Loading branch information
1 parent
0681c45
commit dd5fd6d
Showing
26 changed files
with
249 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
"@rocket.chat/meteor": minor | ||
"@rocket.chat/ui-client": minor | ||
"@rocket.chat/web-ui-registration": minor | ||
--- | ||
|
||
feat: Skip to main content shortcut and useDocumentTitle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { css } from '@rocket.chat/css-in-js'; | ||
import { Box } from '@rocket.chat/fuselage'; | ||
import { useDocumentTitle } from '@rocket.chat/ui-client'; | ||
import { useSetting } from '@rocket.chat/ui-contexts'; | ||
import type { FC } from 'react'; | ||
import React, { useEffect, useCallback } from 'react'; | ||
|
||
import { useUnreadMessages } from './hooks/useUnreadMessages'; | ||
|
||
const useRouteTitleFocus = () => { | ||
return useCallback((node: HTMLElement | null) => { | ||
if (!node) { | ||
return; | ||
} | ||
|
||
node.focus(); | ||
}, []); | ||
}; | ||
|
||
const DocumentTitleWrapper: FC = ({ children }) => { | ||
useDocumentTitle(useSetting<string>('Site_Name') || '', false); | ||
const { title, key } = useDocumentTitle(useUnreadMessages(), false); | ||
|
||
const refocusRef = useRouteTitleFocus(); | ||
|
||
useEffect(() => { | ||
document.title = title; | ||
}, [title]); | ||
|
||
return ( | ||
<> | ||
<Box | ||
tabIndex={-1} | ||
ref={refocusRef} | ||
key={key} | ||
className={css` | ||
position: absolute; | ||
width: 1px; | ||
height: 1px; | ||
padding: 0; | ||
margin: -1px; | ||
overflow: hidden; | ||
clip: rect(0, 0, 0, 0); | ||
white-space: nowrap; | ||
border-width: 0; | ||
`} | ||
> | ||
{title} | ||
</Box> | ||
{children} | ||
</> | ||
); | ||
}; | ||
|
||
export default DocumentTitleWrapper; |
33 changes: 33 additions & 0 deletions
33
apps/meteor/client/views/root/MainLayout/AccessibilityShortcut.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { css } from '@rocket.chat/css-in-js'; | ||
import { Button } from '@rocket.chat/fuselage'; | ||
import { useRouter, useTranslation } from '@rocket.chat/ui-contexts'; | ||
import React from 'react'; | ||
|
||
const AccessibilityShortcut = () => { | ||
const t = useTranslation(); | ||
const router = useRouter(); | ||
const currentRoutePath = router.getLocationPathname(); | ||
|
||
const customButtonClass = css` | ||
position: absolute; | ||
top: 2px; | ||
left: 2px; | ||
z-index: 99; | ||
&:not(:focus) { | ||
width: 1px; | ||
height: 1px; | ||
padding: 0; | ||
overflow: hidden; | ||
clip: rect(1px, 1px, 1px, 1px); | ||
border: 0; | ||
} | ||
`; | ||
|
||
return ( | ||
<Button className={customButtonClass} is='a' href={`${currentRoutePath}#main-content`} primary> | ||
{t('Skip_to_main_content')} | ||
</Button> | ||
); | ||
}; | ||
|
||
export default AccessibilityShortcut; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { useSession, useTranslation } from '@rocket.chat/ui-contexts'; | ||
|
||
export const useUnreadMessages = (): string | undefined => { | ||
const t = useTranslation(); | ||
const unreadMessages = useSession('unread'); | ||
|
||
return (() => { | ||
if (unreadMessages === '') { | ||
return undefined; | ||
} | ||
|
||
return t('unread_messages_counter', { count: unreadMessages }); | ||
})(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.