From 1d5df7a582a2ff738a1b4d6f54ca67fb64aa2508 Mon Sep 17 00:00:00 2001 From: Fernanda Castillo Date: Thu, 12 Dec 2024 14:38:56 +0000 Subject: [PATCH] updates from KO --- .../__e2e__/skip-link/SkipLink.cy.tsx | 10 ++--- packages/lab/src/skip-link/SkipLink.css | 23 +++++++---- packages/lab/src/skip-link/SkipLink.tsx | 38 ++++++++++++------- packages/lab/src/skip-link/SkipLinks.css | 6 --- packages/lab/src/skip-link/SkipLinks.tsx | 29 -------------- packages/lab/src/skip-link/index.ts | 1 - .../stories/skip-link/skip-link.stories.tsx | 36 ++++++------------ 7 files changed, 54 insertions(+), 89 deletions(-) delete mode 100644 packages/lab/src/skip-link/SkipLinks.css delete mode 100644 packages/lab/src/skip-link/SkipLinks.tsx diff --git a/packages/lab/src/__tests__/__e2e__/skip-link/SkipLink.cy.tsx b/packages/lab/src/__tests__/__e2e__/skip-link/SkipLink.cy.tsx index 2f9bf628278..884fece8058 100644 --- a/packages/lab/src/__tests__/__e2e__/skip-link/SkipLink.cy.tsx +++ b/packages/lab/src/__tests__/__e2e__/skip-link/SkipLink.cy.tsx @@ -1,4 +1,4 @@ -import { SkipLink, SkipLinks } from "@salt-ds/lab"; +import { SkipLink } from "@salt-ds/lab"; import * as skipLinkStories from "@stories/skip-link/skip-link.stories"; import { composeStories } from "@storybook/react"; import { checkAccessibility } from "../../../../../../cypress/tests/checkAccessibility"; @@ -14,11 +14,9 @@ const NoTargetRef = () => { Click here and press the Tab key to see the Skip Link
- - - Skip to main content - - + + Skip to main content +
; + target: string; } const withBaseName = makePrefixer("saltSkipLink"); export const SkipLink = forwardRef( - function SkipLink({ className, targetRef, ...rest }, ref) { + function SkipLink({ className, target, children, ...rest }, ref) { const targetWindow = useWindow(); useComponentCssInjection({ testId: "salt-skip-link", @@ -30,19 +30,29 @@ export const SkipLink = forwardRef( window: targetWindow, }); - const targetClass = clsx(withBaseName("target"), className); + const targetRef = useRef(null); - const eventHandlers = useManageFocusOnTarget({ targetRef, targetClass }); + const targetClass = withBaseName("target"); + useEffect(() => { + targetRef.current = document.getElementById(target); + }, [target]); + + const eventHandlers = useManageFocusOnTarget({ + targetRef, + targetClass, + }); return ( -
  • - -
  • + + {children} + ); }, ); diff --git a/packages/lab/src/skip-link/SkipLinks.css b/packages/lab/src/skip-link/SkipLinks.css deleted file mode 100644 index 1752a3e4145..00000000000 --- a/packages/lab/src/skip-link/SkipLinks.css +++ /dev/null @@ -1,6 +0,0 @@ -.saltSkipLinks { - position: relative; - float: left; - list-style: none; - margin: 0; -} diff --git a/packages/lab/src/skip-link/SkipLinks.tsx b/packages/lab/src/skip-link/SkipLinks.tsx deleted file mode 100644 index 7a0b8e83804..00000000000 --- a/packages/lab/src/skip-link/SkipLinks.tsx +++ /dev/null @@ -1,29 +0,0 @@ -import { makePrefixer } from "@salt-ds/core"; -import { clsx } from "clsx"; -import { type HTMLAttributes, forwardRef } from "react"; - -import { useComponentCssInjection } from "@salt-ds/styles"; -import { useWindow } from "@salt-ds/window"; - -import skipLinksCss from "./SkipLinks.css"; - -const withBaseName = makePrefixer("saltSkipLinks"); - -export const SkipLinks = forwardRef< - HTMLUListElement, - HTMLAttributes ->(function SkipLinks(props, ref) { - const { className, children, ...restProps } = props; - const targetWindow = useWindow(); - useComponentCssInjection({ - testId: "salt-skip-links", - css: skipLinksCss, - window: targetWindow, - }); - - return ( -
      - {children} -
    - ); -}); diff --git a/packages/lab/src/skip-link/index.ts b/packages/lab/src/skip-link/index.ts index 1de755de460..cb4f10ea24e 100644 --- a/packages/lab/src/skip-link/index.ts +++ b/packages/lab/src/skip-link/index.ts @@ -1,2 +1 @@ export * from "./SkipLink"; -export * from "./SkipLinks"; diff --git a/packages/lab/stories/skip-link/skip-link.stories.tsx b/packages/lab/stories/skip-link/skip-link.stories.tsx index 3106a6d5916..f043e812331 100644 --- a/packages/lab/stories/skip-link/skip-link.stories.tsx +++ b/packages/lab/stories/skip-link/skip-link.stories.tsx @@ -7,9 +7,8 @@ import { StackLayout, Text, } from "@salt-ds/core"; -import { SkipLink, SkipLinks } from "@salt-ds/lab"; +import { SkipLink } from "@salt-ds/lab"; import type { Meta, StoryFn } from "@storybook/react"; -import { useRef } from "react"; export default { title: "Lab/Skip Link", @@ -17,23 +16,19 @@ export default { } as Meta; export const Default: StoryFn = () => { - const articleRef = useRef(null); - return ( Click here and press the Tab key to see the Skip Link -
    - - - Skip to main content - - +
    + + Skip to main content +

    What we do

    -
    +

    Salt

    @@ -66,28 +61,19 @@ export const Default: StoryFn = () => { }; export const MultipleLinks: StoryFn = () => { - const sectionRef1 = useRef(null); - const sectionRef2 = useRef(null); - return ( Click here and press the Tab key to see the Skip Link -

    - - - Skip to Introduction - - - Skip to Goals - - +
    + Skip to Introduction + Skip to Goals

    What we do

    -
    +

    Salt

    Salt provides you with a suite of UI components and a flexible @@ -98,7 +84,7 @@ export const MultipleLinks: StoryFn = () => { variations, or in fact substitute alternate themes.

    -
    +

    Goals

    Salt has been developed with the following design goals: