@purpurds/autocomplete 7.3.0 → 7.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@purpurds/autocomplete",
3
- "version": "7.3.0",
3
+ "version": "7.4.0",
4
4
  "license": "AGPL-3.0-only",
5
5
  "main": "./dist/autocomplete.cjs.js",
6
6
  "types": "./dist/autocomplete.d.ts",
@@ -17,13 +17,13 @@
17
17
  "dependencies": {
18
18
  "classnames": "~2.5.0",
19
19
  "eslint": "9.24.0",
20
- "@purpurds/heading": "7.3.0",
21
- "@purpurds/listbox": "7.3.0",
22
- "@purpurds/notification": "7.3.0",
23
- "@purpurds/paragraph": "7.3.0",
24
- "@purpurds/text-field": "7.3.0",
25
- "@purpurds/icon": "7.3.0",
26
- "@purpurds/tokens": "7.3.0"
20
+ "@purpurds/icon": "7.4.0",
21
+ "@purpurds/listbox": "7.4.0",
22
+ "@purpurds/heading": "7.4.0",
23
+ "@purpurds/notification": "7.4.0",
24
+ "@purpurds/paragraph": "7.4.0",
25
+ "@purpurds/text-field": "7.4.0",
26
+ "@purpurds/tokens": "7.4.0"
27
27
  },
28
28
  "devDependencies": {
29
29
  "@storybook/blocks": "^8.6.4",
@@ -45,11 +45,11 @@
45
45
  "typescript": "^5.6.3",
46
46
  "vite": "^6.2.1",
47
47
  "vitest": "^3.1.2",
48
- "@purpurds/button": "7.3.0",
48
+ "@purpurds/button": "7.4.0",
49
49
  "@purpurds/component-rig": "1.0.0",
50
- "@purpurds/icon": "7.3.0",
51
- "@purpurds/label": "7.3.0",
52
- "@purpurds/search-field": "7.3.0"
50
+ "@purpurds/icon": "7.4.0",
51
+ "@purpurds/label": "7.4.0",
52
+ "@purpurds/search-field": "7.4.0"
53
53
  },
54
54
  "peerDependencies": {
55
55
  "@types/react": "^18 || ^19",
@@ -138,7 +138,7 @@ export const WithTextField: Story = {
138
138
  <TextField
139
139
  {...inputProps}
140
140
  label="With Text Field"
141
- id="autocomplete-input"
141
+ id={`${args.id}-autocomplete-input`}
142
142
  type="text"
143
143
  placeholder="Enter a fruit"
144
144
  />
@@ -202,14 +202,14 @@ export const WithSearchField: Story = {
202
202
  <SearchField
203
203
  {...inputProps}
204
204
  label="With Search Field"
205
- id="autocomplete-input"
205
+ id={`${args.id}-autocomplete-input`}
206
206
  type="text"
207
207
  onClear={() => {
208
208
  setInputValue("");
209
209
  updateArgs({ selectedOption: undefined });
210
210
  }}
211
211
  placeholder="Find your fruit"
212
- clearButtonAllyLabel="Clear search field"
212
+ clearButtonAriaLabel="Clear search field"
213
213
  variant="button-attached"
214
214
  iconOnlySearchButton
215
215
  searchButtonLabel="Search"
@@ -297,7 +297,6 @@ export const WithRenderOption: Story = {
297
297
  {parts
298
298
  .filter((part) => part)
299
299
  .map((part, i) =>
300
-
301
300
  regex.test(part) ? <strong key={i}>{part}</strong> : <span key={i}>{part}</span>
302
301
  )}
303
302
  </Paragraph>
@@ -307,7 +306,7 @@ export const WithRenderOption: Story = {
307
306
  <TextField
308
307
  {...inputProps}
309
308
  label="With renderOption"
310
- id="autocomplete-input"
309
+ id={`${args.id}-autocomplete-input`}
311
310
  type="text"
312
311
  placeholder="Enter a fruit"
313
312
  />
@@ -318,3 +317,83 @@ export const WithRenderOption: Story = {
318
317
  },
319
318
  tags: ["visual:check"],
320
319
  };
320
+
321
+ export const WithCombobox: Story = {
322
+ args: {
323
+ id: "with-combobox",
324
+ },
325
+ argTypes: {
326
+ listboxMaxHeight: { type: "string" },
327
+ inputValue: { table: { disabled: true } },
328
+ onInputChange: { table: { disabled: true } },
329
+ },
330
+ parameters: {
331
+ docs: {
332
+ source: {
333
+ code: `
334
+ <Autocomplete
335
+ selectedOption={selectedOption}
336
+ noOptionsText="That is not a fruit... Try again!"
337
+ /*
338
+ * NOTE! To handle input change events, always use onInputChange on Autocomplete instead of
339
+ * onChange on the input (SearchField). Autocomplete internally uses onChange on the input,
340
+ * and setting it yourself will override this.
341
+ */
342
+ onInputChange={(value) => {
343
+ setInputValue(value);
344
+ }}
345
+ renderInput={(inputProps) => (
346
+ <TextField
347
+ {...inputProps}
348
+ />
349
+ )}
350
+ combobox
351
+ />`,
352
+ },
353
+ },
354
+ },
355
+ render: ({ ...args }) => {
356
+ const [inputValue, setInputValue] = useState(""); // eslint-disable-line react-hooks/rules-of-hooks
357
+ const [{ selectedOption }, updateArgs] = useArgs(); // eslint-disable-line react-hooks/rules-of-hooks
358
+
359
+ return (
360
+ <>
361
+ <Autocomplete
362
+ {...args}
363
+ selectedOption={selectedOption}
364
+ onSelect={(selectedOption) => updateArgs({ selectedOption })}
365
+ onInputChange={setInputValue}
366
+ inputValue={inputValue}
367
+ renderInput={(inputProps) => (
368
+ <TextField
369
+ {...inputProps}
370
+ id={`${args.id}-autocomplete-input`}
371
+ type="text"
372
+ onClear={() => {
373
+ setInputValue("");
374
+ updateArgs({ selectedOption: undefined });
375
+ }}
376
+ placeholder="Find your fruit"
377
+ clearButtonAllyLabel="Clear text field"
378
+ />
379
+ )}
380
+ combobox
381
+ />
382
+ <div style={{ marginTop: "var(--purpur-spacing-150)", marginRight: "-200px" }}>
383
+ <Notification status="warning" heading="Known issue in Storybook">
384
+ <Paragraph>
385
+ The chevron button used to toggle the suggestions list may behave inconsistently in
386
+ this Storybook environment.
387
+ </Paragraph>
388
+ <Paragraph style={{ marginTop: "var(--purpur-spacing-150)" }}>
389
+ <b>However, this issue does not occur in a real application.</b> In actual usage, the
390
+ chevron correctly toggles the list as expected.
391
+ </Paragraph>
392
+ </Notification>
393
+ </div>
394
+ <OnInputEventPitfallNotification />
395
+ </>
396
+ );
397
+ },
398
+ tags: ["visual:check"],
399
+ };
package/src/utils.ts CHANGED
@@ -3,7 +3,7 @@ import { MutableRefObject, useCallback, useEffect, useRef } from "react";
3
3
  // Used to "merge" "intersection types". Used to get comments on the props to the docs.
4
4
  export type Prettify<T> = {
5
5
  [K in keyof T]: T[K];
6
- } & {};
6
+ } & {};
7
7
 
8
8
  export const useMutableRefObject = <T>(value: T): MutableRefObject<T> => {
9
9
  return useRef<T>(value) as MutableRefObject<T>;