Skip to content

Commit

Permalink
feat: picker zero selection (#6780)
Browse files Browse the repository at this point in the history
* picker zero items

* Change files

* prettier

* default to null

* update files
  • Loading branch information
Stephane Comeau authored Aug 8, 2023
1 parent 50dba9c commit e0d4cb4
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "picker zero items",
"packageName": "@microsoft/fast-foundation",
"email": "[email protected]",
"dependentChangeType": "prerelease"
}
2 changes: 1 addition & 1 deletion packages/web-components/fast-foundation/docs/api-report.md
Original file line number Diff line number Diff line change
Expand Up @@ -1547,7 +1547,7 @@ export class FASTPicker extends FormAssociatedPicker {
// (undocumented)
protected listItemTemplateChanged(): void;
loadingText: string;
maxSelected: number | undefined;
maxSelected: number | null;
// @internal
menuConfig: AnchoredRegionConfig;
// @internal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ export class FASTTextField extends TextField {}
| `options` | public | `string` | | Currently available options. Comma delineated string ie. "apples,oranges". | |
| `filterSelected` | public | `boolean` | `true` | Whether the component should remove an option from the list when it is in the selection | |
| `filterQuery` | public | `boolean` | `true` | Whether the component should remove options based on the current query | |
| `maxSelected` | public | `number or undefined` | | The maximum number of items that can be selected. | |
| `maxSelected` | public | `number or null` | `null` | The maximum number of items that can be selected. | |
| `noSuggestionsText` | public | `string` | `"No suggestions available"` | The text to present to assistive technolgies when no suggestions are available. | |
| `suggestionsAvailableText` | public | `string` | `"Suggestions available"` | The text to present to assistive technolgies when suggestions are available. | |
| `loadingText` | public | `string` | `"Loading suggestions"` | The text to present to assistive technologies when suggestions are loading. | |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Picker is the top level container which hosts both a `picker-list` component to
*Attributes:*
- `selection`: List of currently selected items. Comma delineated string ie. "apples,oranges".
- `options`: Currently available options. Comma delineated string ie. "apples,oranges".
- `max-selected`: The maximum number of items that can be selected. Unset by default (ie. no maximum).
- `max-selected`: The maximum number of items that can be selected. Unset by default (ie. no maximum). If the value is "0" selecting an item updates the query instead.
- `no-suggestions-text`: The text to present when no suggestions are available.
- `suggestions-available-text`: The text to present when suggestions are available.
- `loading-text`: The text to present when suggestions are loading.
Expand Down
25 changes: 14 additions & 11 deletions packages/web-components/fast-foundation/src/picker/picker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
attr,
html,
HTMLView,
nullableNumberConverter,
observable,
oneWay,
ref,
Expand Down Expand Up @@ -117,8 +118,8 @@ export class FASTPicker extends FormAssociatedPicker {
* @remarks
* HTML Attribute: max-selected
*/
@attr({ attribute: "max-selected" })
public maxSelected: number | undefined;
@attr({ attribute: "max-selected", converter: nullableNumberConverter })
public maxSelected: number | null = null;

/**
* The text to present to assistive technolgies when no suggestions are available.
Expand Down Expand Up @@ -806,7 +807,8 @@ export class FASTPicker extends FormAssociatedPicker {
return;
}
if (
this.maxSelected !== undefined &&
this.maxSelected !== null &&
this.maxSelected !== 0 &&
this.selectedItems.length >= this.maxSelected
) {
if (this.getRootActiveElement() === this.inputElement) {
Expand Down Expand Up @@ -867,21 +869,22 @@ export class FASTPicker extends FormAssociatedPicker {
return false;
}

if (e.target instanceof FASTPickerMenuOption) {
if (e.target.value !== undefined) {
if (e.target instanceof FASTPickerMenuOption && e.target.value !== undefined) {
if (this.maxSelected === 0) {
// if we don't allow selection just update the query
this.query = e.target.value;
} else {
this.query = "";
this.selection = `${this.selection}${this.selection === "" ? "" : ","}${
e.target.value
}`;
}
this.inputElement.value = "";
this.query = "";
this.inputElement.focus();

this.toggleFlyout(false);
this.inputElement.focus();
return false;
}

// const value: string = (e.target as PickerMenuOption).value;

return true;
}

Expand Down Expand Up @@ -913,7 +916,7 @@ export class FASTPicker extends FormAssociatedPicker {
);
if (newFocusedItemIndex === selectedItemsAsElements.length) {
if (
this.maxSelected !== undefined &&
this.maxSelected !== null &&
this.selectedItems.length >= this.maxSelected
) {
(
Expand Down

0 comments on commit e0d4cb4

Please sign in to comment.