diff --git a/packages/core/src/components/menu/menuItem.tsx b/packages/core/src/components/menu/menuItem.tsx index 1471f5a1f3..3599c99a9c 100644 --- a/packages/core/src/components/menu/menuItem.tsx +++ b/packages/core/src/components/menu/menuItem.tsx @@ -35,15 +35,7 @@ export interface IMenuItemProps extends ActionProps, LinkProps { text: React.ReactNode; /** - * Whether this item should render with an active appearance. - * This is the same styling as the `:active` CSS element state. - * - * Note: in Blueprint 3.x, this prop was conflated with a "selected" appearance - * when `intent` was undefined. For legacy purposes, we emulate this behavior in - * Blueprint 4.x, so setting `active={true} intent={undefined}` is the same as - * `selected={true}`. This prop will be removed in a future major version. - * - * @deprecated use `selected` prop + * Whether this item should render with an active appearance. Used to indicate keyboard focus. */ active?: boolean; @@ -117,7 +109,7 @@ export interface IMenuItemProps extends ActionProps, LinkProps { popoverProps?: Partial; /** - * Whether this item should appear selected. + * Whether this item is selected. This will set the `aria-selected` attribute. */ selected?: boolean; diff --git a/packages/core/test/menu/menuItemTests.tsx b/packages/core/test/menu/menuItemTests.tsx index 9a0f8423d2..fbd077f756 100644 --- a/packages/core/test/menu/menuItemTests.tsx +++ b/packages/core/test/menu/menuItemTests.tsx @@ -72,8 +72,9 @@ describe("MenuItem", () => { }); it("can set roleStructure to change role prop structure to that of a listbox or select item", () => { - const wrapper = mount(); + const wrapper = mount(); assert.equal(wrapper.find("li").prop("role"), "option"); + assert.equal(wrapper.find("li").prop("aria-selected"), true); assert.equal(wrapper.find("a").prop("role"), undefined); }); diff --git a/packages/docs-app/src/common/filmSelect.tsx b/packages/docs-app/src/common/filmSelect.tsx index 7f06ed4357..d30c8b3040 100644 --- a/packages/docs-app/src/common/filmSelect.tsx +++ b/packages/docs-app/src/common/filmSelect.tsx @@ -18,12 +18,13 @@ import * as React from "react"; import { Button } from "@blueprintjs/core"; import { MenuItem2 } from "@blueprintjs/popover2"; -import { Select2, Select2Props } from "@blueprintjs/select"; +import { ItemRenderer, Select2, Select2Props } from "@blueprintjs/select"; import { areFilmsEqual, createFilm, - filmSelectProps, + filterFilm, + getFilmItemProps, IFilm, maybeAddCreatedFilmToArrays, maybeDeleteCreatedFilmFromArrays, @@ -37,11 +38,12 @@ type Props = Omit< Select2Props, | "createNewItemFromQuery" | "createNewItemRenderer" + | "itemPredicate" + | "itemRenderer" | "items" | "itemsEqual" | "noResults" | "onItemSelect" - | keyof typeof filmSelectProps > & { allowCreate?: boolean; }; @@ -51,38 +53,49 @@ export default function ({ allowCreate = false, fill, ...restProps }: Props) { const maybeCreateNewItemFromQuery = allowCreate ? createFilm : undefined; const maybeCreateNewItemRenderer = allowCreate ? renderCreateFilmOption : null; - const [items, setItems] = React.useState(filmSelectProps.items); + const [items, setItems] = React.useState([...TOP_100_FILMS]); const [createdItems, setCreatedItems] = React.useState([]); - const [film, setFilm] = React.useState(TOP_100_FILMS[0]); + const [selectedFilm, setSelectedFilm] = React.useState(TOP_100_FILMS[0]); const handleItemSelect = React.useCallback((newFilm: IFilm) => { // Delete the old film from the list if it was newly created. - const step1Result = maybeDeleteCreatedFilmFromArrays(items, createdItems, film); + const step1Result = maybeDeleteCreatedFilmFromArrays(items, createdItems, selectedFilm); // Add the new film to the list if it is newly created. const step2Result = maybeAddCreatedFilmToArrays(step1Result.items, step1Result.createdItems, newFilm); setCreatedItems(step2Result.createdItems); - setFilm(newFilm); + setSelectedFilm(newFilm); setItems(step2Result.items); }, []); + const itemRenderer = React.useCallback>( + (film, props) => { + if (!props.modifiers.matchesPredicate) { + return null; + } + return ; + }, + [selectedFilm], + ); + return ( } onItemSelect={handleItemSelect} - items={items} - fill={fill} {...restProps} >