Aitema-gmbh commented on code in PR #39240: URL: https://github.com/apache/superset/pull/39240#discussion_r3232487952
########## superset-frontend/src/components/Accessibility/SkipLink.tsx: ########## @@ -0,0 +1,99 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +import { FC, MouseEvent } from 'react'; +import { styled } from '@apache-superset/core/theme'; + +/** + * SkipLink - WCAG 2.4.1 Bypass Blocks + * Allows keyboard users to skip navigation and jump directly to main content. + * The link is visually hidden but becomes visible when focused. + */ + +const StyledSkipLink = styled.a` + position: absolute; + top: -100px; + left: 0; + background: ${({ theme }) => theme.colorPrimary}; + color: ${({ theme }) => theme.colorWhite}; + padding: ${({ theme }) => theme.sizeUnit * 3}px + ${({ theme }) => theme.sizeUnit * 4}px; + z-index: 10000; + text-decoration: none; + font-weight: ${({ theme }) => theme.fontWeightStrong}; + font-size: ${({ theme }) => theme.fontSizeSM}px; + border-radius: 0 0 ${({ theme }) => theme.borderRadius}px + ${({ theme }) => theme.borderRadius}px; + transition: top 0.2s ease-in-out; + + &:focus, + &:focus-visible { + top: 0 !important; + outline: 3px solid ${({ theme }) => theme.colorPrimaryBorderHover}; + outline-offset: 2px; + } + + &:hover { + background: ${({ theme }) => theme.colorPrimaryHover}; + } +`; + +interface SkipLinkProps { + targetId?: string; + children?: React.ReactNode; +} + +const SkipLink: FC<SkipLinkProps> = ({ + targetId = 'main-content', + children = 'Skip to main content', Review Comment: Addressed in 73d91f5a — SkipLink.tsx now imports t from @apache-superset/core/translation and uses t('Skip to main content') as the default children. Resolving — thanks for the catch. ########## superset-frontend/src/components/Accessibility/SkipLink.tsx: ########## @@ -0,0 +1,100 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +import { FC, MouseEvent } from 'react'; +import { styled } from '@apache-superset/core/theme'; +import { t } from '@apache-superset/core/translation'; + +/** + * SkipLink - WCAG 2.4.1 Bypass Blocks + * Allows keyboard users to skip navigation and jump directly to main content. + * The link is visually hidden but becomes visible when focused. + */ + +const StyledSkipLink = styled.a` + position: absolute; + top: -100px; + left: 0; + background: ${({ theme }) => theme.colorPrimary}; + color: ${({ theme }) => theme.colorWhite}; + padding: ${({ theme }) => theme.sizeUnit * 3}px + ${({ theme }) => theme.sizeUnit * 4}px; + z-index: 10000; + text-decoration: none; + font-weight: ${({ theme }) => theme.fontWeightStrong}; + font-size: ${({ theme }) => theme.fontSizeSM}px; + border-radius: 0 0 ${({ theme }) => theme.borderRadius}px + ${({ theme }) => theme.borderRadius}px; + transition: top 0.2s ease-in-out; + + &:focus, + &:focus-visible { + top: 0 !important; + outline: 3px solid ${({ theme }) => theme.colorPrimaryBorderHover}; + outline-offset: 2px; + } + + &:hover { + background: ${({ theme }) => theme.colorPrimaryHover}; + } +`; + +interface SkipLinkProps { + targetId?: string; + children?: React.ReactNode; +} + +const SkipLink: FC<SkipLinkProps> = ({ + targetId = 'main-content', + children = t('Skip to main content'), +}) => { + const handleClick = (e: MouseEvent<HTMLAnchorElement>) => { + e.preventDefault(); + const el = document.getElementById(targetId); + if (el) { + // Temporarily set tabindex to allow programmatic focus, + // then remove it on blur so the element stays in the natural tab order + const hadTabindex = el.hasAttribute('tabindex'); + if (!hadTabindex) { + el.setAttribute('tabindex', '-1'); + } + el.focus(); + if (!hadTabindex) { + el.addEventListener( + 'blur', + () => el.removeAttribute('tabindex'), + { once: true }, + ); + } + } else { + window.location.hash = `#${targetId}`; + } + }; Review Comment: Addressed in 70c7be13 — SkipLink.test.tsx adds six tests covering the default label, custom children, default and custom targetId in href, focus-on-click, and tabindex cleanup on blur (Jest + RTL + userEvent). Resolving — thanks for the catch. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
