Skip to content

Commit

Permalink
targetid
Browse files Browse the repository at this point in the history
  • Loading branch information
Fercas123 committed Dec 19, 2024
1 parent 1bea029 commit 394ac35
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe("GIVEN a SkipLink", () => {
});

it("THEN it should hide the skip link if ref is broken", () => {
cy.mount(<Default target="" />);
cy.mount(<Default targetId="" />);
cy.findByText(
"Click here and press the Tab key to see the Skip Link",
).click();
Expand Down
10 changes: 5 additions & 5 deletions packages/lab/src/skip-link/SkipLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ interface SkipLinkProps extends ComponentPropsWithoutRef<"a"> {
* The ID of the target element to apply focus when the link is clicked.
* If the element with this ID is not found, the SkipLink will not be rendered.
*/
target: string;
targetId: string;
}

const withBaseName = makePrefixer("saltSkipLink");

export const SkipLink = forwardRef<HTMLAnchorElement, SkipLinkProps>(
function SkipLink(
{ className, target, children, onKeyUp, onBlur, onClick, ...rest },
{ className, targetId, children, onKeyUp, onBlur, onClick, ...rest },
ref,
) {
const [isTargetAvailable, setIsTargetAvailable] = useState(false);
Expand All @@ -39,9 +39,9 @@ export const SkipLink = forwardRef<HTMLAnchorElement, SkipLinkProps>(
const targetRef = useRef<HTMLElement | null>(null);

useEffect(() => {
targetRef.current = document.getElementById(target);
targetRef.current = document.getElementById(targetId);
setIsTargetAvailable(!!targetRef.current);
}, [target]);
}, [targetId]);

const eventHandlers = useManageFocusOnTarget({
onKeyUp,
Expand All @@ -55,7 +55,7 @@ export const SkipLink = forwardRef<HTMLAnchorElement, SkipLinkProps>(
return (
<a
className={clsx(withBaseName(), className)}
href={`#${target}`}
href={`#${targetId}`}
ref={ref}
target="_self"
{...eventHandlers}
Expand Down
2 changes: 1 addition & 1 deletion packages/lab/stories/skip-link/skip-link.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ const DefaultStory: StoryFn<typeof SkipLink> = (args) => {

export const Default = DefaultStory.bind({});
Default.args = {
target: "main",
targetId: "main",
};
Default.parameters = {
layout: "fullscreen",
Expand Down

0 comments on commit 394ac35

Please sign in to comment.