From 44c14e5ad0c851ce66adee324529733ff6ea5828 Mon Sep 17 00:00:00 2001 From: Adi Dahiya Date: Tue, 17 May 2022 13:29:53 -0400 Subject: [PATCH] [select] feat: new Select2 component uses Popover2 (#5306) --- packages/docs-app/src/common/filmSelect.tsx | 6 +- .../select-examples/selectExample.tsx | 1 + packages/select/karma.conf.js | 1 - packages/select/package.json | 1 + packages/select/src/components/index.ts | 1 + .../select/src/components/select/_select.scss | 3 +- .../src/components/select/select-component.md | 279 +---------------- .../select/src/components/select/select.tsx | 1 + .../select/src/components/select/select2.md | 294 ++++++++++++++++++ .../select/src/components/select/select2.tsx | 255 +++++++++++++++ packages/select/src/index.md | 13 +- packages/select/test/index.ts | 1 + packages/select/test/isotest.js | 9 +- packages/select/test/select2Tests.tsx | 123 ++++++++ packages/select/test/selectTests.tsx | 16 +- 15 files changed, 722 insertions(+), 282 deletions(-) create mode 100644 packages/select/src/components/select/select2.md create mode 100644 packages/select/src/components/select/select2.tsx create mode 100644 packages/select/test/select2Tests.tsx diff --git a/packages/docs-app/src/common/filmSelect.tsx b/packages/docs-app/src/common/filmSelect.tsx index 6421a08c40..b97d987f3a 100644 --- a/packages/docs-app/src/common/filmSelect.tsx +++ b/packages/docs-app/src/common/filmSelect.tsx @@ -17,7 +17,7 @@ import * as React from "react"; import { Button, MenuItem } from "@blueprintjs/core"; -import { Select, SelectProps } from "@blueprintjs/select"; +import { Select2, Select2Props } from "@blueprintjs/select"; import { areFilmsEqual, @@ -30,10 +30,10 @@ import { TOP_100_FILMS, } from "./films"; -const FilmSelect = Select.ofType(); +const FilmSelect = Select2.ofType(); type Props = Omit< - SelectProps, + Select2Props, | "createNewItemFromQuery" | "createNewItemRenderer" | "items" diff --git a/packages/docs-app/src/examples/select-examples/selectExample.tsx b/packages/docs-app/src/examples/select-examples/selectExample.tsx index 0c4f62d92a..9b9d977409 100644 --- a/packages/docs-app/src/examples/select-examples/selectExample.tsx +++ b/packages/docs-app/src/examples/select-examples/selectExample.tsx @@ -38,6 +38,7 @@ export interface ISelectExampleState { matchTargetWidth: false; } +/** Technically a Select2 example, since FilmSelect uses Select2. */ export class SelectExample extends React.PureComponent { public state: ISelectExampleState = { allowCreate: false, diff --git a/packages/select/karma.conf.js b/packages/select/karma.conf.js index c46c44bbae..84c3e0b538 100644 --- a/packages/select/karma.conf.js +++ b/packages/select/karma.conf.js @@ -6,7 +6,6 @@ const { createKarmaConfig } = require("@blueprintjs/karma-build-scripts"); module.exports = function (config) { const baseConfig = createKarmaConfig({ - coverage: false, dirname: __dirname, }); config.set(baseConfig); diff --git a/packages/select/package.json b/packages/select/package.json index 3f52684a8f..737ee72c5f 100644 --- a/packages/select/package.json +++ b/packages/select/package.json @@ -36,6 +36,7 @@ }, "dependencies": { "@blueprintjs/core": "^4.3.2", + "@blueprintjs/popover2": "^1.2.2", "classnames": "^2.2", "tslib": "~2.3.1" }, diff --git a/packages/select/src/components/index.ts b/packages/select/src/components/index.ts index d5bcf0b20c..743b61dc88 100644 --- a/packages/select/src/components/index.ts +++ b/packages/select/src/components/index.ts @@ -18,4 +18,5 @@ export * from "./omnibar/omnibar"; export * from "./query-list/queryList"; export * from "./select/multiSelect"; export * from "./select/select"; +export * from "./select/select2"; export * from "./select/suggest"; diff --git a/packages/select/src/components/select/_select.scss b/packages/select/src/components/select/_select.scss index e33c312bc0..d6386636a3 100644 --- a/packages/select/src/components/select/_select.scss +++ b/packages/select/src/components/select/_select.scss @@ -16,7 +16,8 @@ $select-popover-max-width: $pt-grid-size * 40 !default; } } - .#{$ns}-popover-content { + .#{$ns}-popover-content, + .#{$ns}-popover2-content { // use padding on container rather than margin on input group // because top margin leaves some empty space with no background color. padding: $pt-grid-size * 0.5; diff --git a/packages/select/src/components/select/select-component.md b/packages/select/src/components/select/select-component.md index 92e9d0513c..e3ff6f8f89 100644 --- a/packages/select/src/components/select/select-component.md +++ b/packages/select/src/components/select/select-component.md @@ -1,276 +1,27 @@ @# Select -Use `Select` for choosing one item from a list. The component's children will be wrapped in a [`Popover`](#core/components/popover) that contains the list and an optional `InputGroup` to filter it. Provide a predicate to customize the filtering algorithm. The value of a `Select` (the currently chosen item) is uncontrolled: listen to changes with `onItemSelect`. +
+

-
-

Disabling a Select

+Deprecated: use [Select2](#select/select2) -Disabling the component requires setting the `disabled` prop to `true` -and separately disabling the component's children as appropriate (because `Select` accepts arbitrary children). +

-For example, `` +This component is **deprecated since @blueprintjs/select v4.3.0** in favor of the new +Select2 component, which uses Popover2 instead of Popover under the hood. +You should migrate to the new API which will become the standard in Blueprint v5.
-@reactExample SelectExample +The `Select` component renders a UI to choose one item from a list. Its children are wrapped in a +[`Popover`](#core/components/popover) that contains the list and an optional `InputGroup` to filter it. +You may provide a predicate to customize the filtering algorithm. The value of a `Select` +(the currently chosen item) is uncontrolled: listen to changes with `onItemSelect`. -```tsx -import { Button, MenuItem } from "@blueprintjs/core"; -import { Select } from "@blueprintjs/select"; -import * as Films from "./films"; +The API for this component is nearly identical to that of Select2, except for a slight change in +`popoverProps` and the wrapper element(s) rendered around its children. +Refer to the [Select2 documentation](#select/select2) for full API details. -// Select is a generic component to work with your data types. -// In TypeScript, you must first obtain a non-generic reference: -const FilmSelect = Select.ofType(); - -ReactDOM.render( - } - onItemSelect={...} - > - {/* children become the popover target; render value here */} - + , + ); + if (query !== undefined) { + wrapper.setState({ query }); + } + return wrapper; + } +}); + +function filterByYear(query: string, film: IFilm) { + return query === "" || film.year.toString() === query; +} diff --git a/packages/select/test/selectTests.tsx b/packages/select/test/selectTests.tsx index 721a163747..4bae9c129f 100644 --- a/packages/select/test/selectTests.tsx +++ b/packages/select/test/selectTests.tsx @@ -19,7 +19,7 @@ import { mount } from "enzyme"; import * as React from "react"; import * as sinon from "sinon"; -import { InputGroup, Popover } from "@blueprintjs/core"; +import { InputGroup, Keys, Popover } from "@blueprintjs/core"; import { IFilm, renderFilm, TOP_100_FILMS } from "../../docs-app/src/common/films"; import { IItemRendererProps, ISelectProps, ISelectState, Select } from "../src"; @@ -92,18 +92,26 @@ describe("