Skip to content

Commit

Permalink
Use useId to generate unqiue ids for accessibility attributes.
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeer committed Dec 17, 2024
1 parent 41e2a86 commit 07d6865
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/components/SearchHit.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useMemo } from 'react';
import { useEffect, useId, useMemo } from 'react';
import { useEffectEvent } from 'use-effect-event';
import PropTypes from 'prop-types';
import Button from '@mui/material/Button';
Expand Down Expand Up @@ -86,11 +86,12 @@ export function SearchHit({
);
});

const canvasLabelHtmlId = useId();

if (focused && !selected) return null;

const renderedHit = focused ? hit : hit && truncatedHit;
const truncated = hit && (renderedHit.before !== hit.before || renderedHit.after !== hit.after);
const canvasLabelHtmlId = `${companionWindowId}-${index}`;
const ownerState = {
adjacent, focused, selected, windowSelected,
};
Expand Down
4 changes: 2 additions & 2 deletions src/components/WindowTopBarPluginMenu.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useContext, useState } from 'react';
import { useContext, useId, useState } from 'react';
import PropTypes from 'prop-types';
import MoreVertIcon from '@mui/icons-material/MoreVertSharp';
import Menu from '@mui/material/Menu';
Expand All @@ -18,6 +18,7 @@ export function WindowTopBarPluginMenu({
const pluginProps = arguments[0]; // eslint-disable-line prefer-rest-params
const [anchorEl, setAnchorEl] = useState(null);
const [open, setOpen] = useState(false);
const windowPluginMenuId = useId();

/** */
const handleMenuClick = (event) => {
Expand All @@ -31,7 +32,6 @@ export function WindowTopBarPluginMenu({
setOpen(false);
};

const windowPluginMenuId = `window-plugin-menu_${windowId}`;
if (!PluginComponents || PluginComponents.length === 0) return null;

return (
Expand Down
4 changes: 2 additions & 2 deletions src/components/WindowTopMenuButton.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState } from 'react';
import { useId, useState } from 'react';
import PropTypes from 'prop-types';
import { useTranslation } from 'react-i18next';
import WindowTopMenu from '../containers/WindowTopMenu';
Expand All @@ -11,6 +11,7 @@ export function WindowTopMenuButton({ classes = {}, windowId }) {
const { t } = useTranslation();
const [anchorEl, setAnchorEl] = useState(null);
const [open, setOpen] = useState(false);
const menuId = useId();

/** */
const handleMenuClick = (event) => {
Expand All @@ -24,7 +25,6 @@ export function WindowTopMenuButton({ classes = {}, windowId }) {
setOpen(false);
};

const menuId = `window-menu_${windowId}`;
return (
<>
<MiradorMenuButton
Expand Down

0 comments on commit 07d6865

Please sign in to comment.