codeant-ai-for-open-source[bot] commented on code in PR #38256: URL: https://github.com/apache/superset/pull/38256#discussion_r2854576655
########## superset-frontend/src/components/ScrollToBottom/index.tsx: ########## @@ -0,0 +1,103 @@ +/** + * 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 { useEffect, useState, useCallback } from 'react'; +import { styled, SupersetTheme } from '@apache-superset/core/ui'; +import { t } from '@superset-ui/core'; +import { Icons } from '@superset-ui/core/components/Icons'; +import { Tooltip } from '@superset-ui/core/components'; + +const SCROLL_THRESHOLD = 100; + +const StyledScrollButton = styled.div` + position: fixed; + bottom: ${({ theme }: { theme: SupersetTheme }) => theme.sizeUnit * 5}px; + right: ${({ theme }: { theme: SupersetTheme }) => theme.sizeUnit * 5}px; + z-index: ${({ theme }: { theme: SupersetTheme }) => theme.zIndexPopupBase + 10}; + cursor: pointer; + background-color: ${({ theme }: { theme: SupersetTheme }) => theme.colorPrimary}; + color: ${({ theme }: { theme: SupersetTheme }) => theme.colorTextLightSolid}; + width: ${({ theme }: { theme: SupersetTheme }) => theme.sizeUnit * 10}px; + height: ${({ theme }: { theme: SupersetTheme }) => theme.sizeUnit * 10}px; + border-radius: 50%; + display: flex; + align-items: center; + justify-content: center; + box-shadow: ${({ theme }: { theme: SupersetTheme }) => theme.boxShadow}; + transition: all ${({ theme }: { theme: SupersetTheme }) => + theme.motionDurationMid}; + opacity: 0; + visibility: hidden; + transform: translateY(20px); + + &.visible { + opacity: 1; + visibility: visible; + transform: translateY(0); + } + + &:hover { + background-color: ${({ theme }: { theme: SupersetTheme }) => + theme.colorPrimaryHover}; + box-shadow: ${({ theme }: { theme: SupersetTheme }) => + theme.boxShadowSecondary}; + } + + .anticon { + font-size: ${({ theme }: { theme: SupersetTheme }) => + theme.fontSizeHeading3}px; + } +`; + +const ScrollToBottom = () => { + const [isVisible, setIsVisible] = useState(false); + + const toggleVisibility = useCallback(() => { + const { scrollHeight, scrollTop, clientHeight } = document.documentElement; + // Show button if we are NOT at the bottom + const isAtBottom = scrollHeight - scrollTop - clientHeight < SCROLL_THRESHOLD; + setIsVisible(!isAtBottom && scrollTop > SCROLL_THRESHOLD); + }, []); + + useEffect(() => { + window.addEventListener('scroll', toggleVisibility); + return () => window.removeEventListener('scroll', toggleVisibility); + }, [toggleVisibility]); + + const scrollToBottom = () => { + window.scrollTo({ + top: document.documentElement.scrollHeight, + behavior: 'smooth', + }); + }; + + return ( + <Tooltip title={t('Scroll to bottom')} placement="left"> + <StyledScrollButton + className={isVisible ? 'visible' : ''} + onClick={scrollToBottom} + role="button" + aria-label={t('Scroll to bottom')} + > + <Icons.DownOutlined /> + </StyledScrollButton> + </Tooltip> + ); Review Comment: **Suggestion:** The scroll-to-bottom control is rendered as a div with role="button" but is not keyboard-focusable and does not respond to keyboard events, so keyboard-only users cannot activate it, which is a functional accessibility bug. [possible bug] <details> <summary><b>Severity Level:</b> Major ⚠️</summary> ```mdx - ⚠️ Scroll-to-bottom FAB unusable for keyboard-only users. - ⚠️ New global UI control fails accessibility expectations. ``` </details> ```suggestion return ( <Tooltip title={t('Scroll to bottom')} placement="left"> <StyledScrollButton className={isVisible ? 'visible' : ''} onClick={scrollToBottom} role="button" aria-label={t('Scroll to bottom')} tabIndex={0} onKeyDown={event => { if (event.key === 'Enter' || event.key === ' ') { event.preventDefault(); scrollToBottom(); } }} > <Icons.DownOutlined /> </StyledScrollButton> </Tooltip> ); ``` <details> <summary><b>Steps of Reproduction ✅ </b></summary> ```mdx 1. Start the Superset frontend with this PR code and navigate to any page where the `ScrollToBottom` component is rendered (the component is defined in `superset-frontend/src/components/ScrollToBottom/index.tsx:67-103`). 2. Using only the keyboard, press `Tab` repeatedly to move focus through interactive elements on the page. 3. Observe that the scroll-to-bottom control rendered by `StyledScrollButton` at `index.tsx:89-98` never receives focus because it is a `<div>` with `role="button"` but no `tabIndex`. 4. Attempt to activate the control via keyboard (e.g., `Enter` or `Space`); no key events are handled on `StyledScrollButton`, so keyboard-only users cannot trigger `scrollToBottom()` at `index.tsx:82-86`, meaning the feature is not operable for them. ``` </details> <details> <summary><b>Prompt for AI Agent 🤖 </b></summary> ```mdx This is a comment left during a code review. **Path:** superset-frontend/src/components/ScrollToBottom/index.tsx **Line:** 89:100 **Comment:** *Possible Bug: The scroll-to-bottom control is rendered as a div with role="button" but is not keyboard-focusable and does not respond to keyboard events, so keyboard-only users cannot activate it, which is a functional accessibility bug. Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise. ``` </details> <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F38256&comment_hash=afaa4d7c11787ea37b884aa7a27d6484ee3802751087359a9b0e10a3d5e76fed&reaction=like'>👍</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F38256&comment_hash=afaa4d7c11787ea37b884aa7a27d6484ee3802751087359a9b0e10a3d5e76fed&reaction=dislike'>👎</a> -- 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]
