Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions packages/oss-components/src/components/o-s-s/infinite-select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,17 @@ export default class OSSInfiniteSelect extends Component<InfiniteSelectSignature
}

private _focusElementAt(index: number): void {
const el = document.querySelectorAll(
this._itemElementAt(index)?.focus();
}

private _itemElementAt(index: number): HTMLElement | undefined {
return document.querySelectorAll<HTMLElement>(
`[data-internal-id="${this.elementId}"] .upf-infinite-select__items-container li`
)[index] as HTMLElement;
el?.focus();
)[index];
}

private _isItemDisabledAt(index: number): boolean {
return Boolean(this._itemElementAt(index)?.querySelector(':scope > .oss-infinite-select-option--disabled'));
}

private _focusInput(): void {
Expand Down Expand Up @@ -310,8 +317,11 @@ export default class OSSInfiniteSelect extends Component<InfiniteSelectSignature
}

private handleEnter(self: any, e: KeyboardEvent): void {
self.didSelectItem(self.itemsInDisplayOrder[self._focusElement]);
e.preventDefault();

if (self._isItemDisabledAt(self._focusElement)) return;

self.didSelectItem(self.itemsInDisplayOrder[self._focusElement]);
}

private handleTab(self: any): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
>
<div class="oss-infinite-select-option__container">
{{#if this.isSelectionMultiple}}
<OSS::Checkbox @checked={{this.selected}} @disabled={{@disabled}} @onChange={{this.onSelect}} />
<OSS::Checkbox @checked={{this.selected}} @size="sm" @disabled={{@disabled}} @onChange={{this.onSelect}} />
{{/if}}
{{#if @prefixAvatar}}
<OSS::Avatar
Expand Down
46 changes: 41 additions & 5 deletions packages/oss-components/src/components/o-s-s/power-select.hbs
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
<div
class="upf-power-select fx-1 fx-col {{if @borderless 'upf-power-select--borderless'}}"
class="upf-power-select fx-1 fx-col
{{if @borderless 'upf-power-select--borderless'}}
{{if @disabled 'upf-power-select--disabled'}}"
data-toggle="oss-dropdown"
{{did-insert this.registerContainer}}
{{did-insert (fn this.ensureBlockPresence (has-block "selected-item") (has-block "option-item"))}}
{{did-insert (fn this.ensureBlockPresence (has-block "selected-item") (has-block "option-item") (has-block "row"))}}
{{did-update this.resetSearch this.isOpen}}
{{will-destroy this.disconnectObserver}}
...attributes
>
<div class="upf-power-select__array-container" role="button" {{on "click" this.toggleDropdown}}>
<div class="array-input-container {{this.inputBorderStateClass}} fx-row padding-px-6 {{if this.isOpen 'active'}}">
<div
class="array-input-container
{{this.inputBorderStateClass}}
fx-row padding-px-6
{{if this.isOpen 'active'}}
{{if @disabled 'array-input-container--disabled'}}"
>
<div class="fx-row fx-xalign-center fx-1 padding-left-px-6 padding-right-px-24 fx-gap-px-6 fx-wrap">
{{#each @selectedItems as |selectedItem index|}}
{{yield selectedItem index to="selected-item"}}
Expand Down Expand Up @@ -48,7 +56,21 @@
{{on-click-outside this.onClickOutside useCapture=@captureClickOutside}}
>
<:option as |item index|>
{{yield item index to="option-item"}}
{{#if (has-block "row")}}
{{yield
item
(component
"o-s-s/infinite-select/option"
selectionType="multiple"
selected=(this.isSelected item=item)
onSelect=(fn this.onSelect item)
)
index
to="row"
}}
{{else}}
{{yield item index to="option-item"}}
{{/if}}
</:option>

<:empty-state>
Expand All @@ -71,7 +93,21 @@
{{on-click-outside this.onClickOutside useCapture=@captureClickOutside}}
>
<:option as |item index|>
{{yield item index to="option-item"}}
{{#if (has-block "row")}}
{{yield
item
(component
"o-s-s/infinite-select/option"
selectionType="multiple"
selected=(this.isSelected item=item)
onSelect=(fn this.onSelect item)
)
index
to="row"
}}
{{else}}
{{yield item index to="option-item"}}
{{/if}}
</:option>
</OSS::InfiniteSelect>
{{/if}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ const Template = (args) => ({
@onSearch={{this.onSearch}} @onChange={{this.onChange}} @loading={{this.loading}}
@borderless={{this.borderless}} @hasError={{this.hasError}} @feedbackMessage={{this.feedbackMessage}}
@loadingMore={{this.loadingMore}} @placeholder={{this.placeholder}} @searchPlaceholder={{this.searchPlaceholder}}
@onBottomReached={{this.onBottomReached}} @addressableAs={{this.addressableAs}}>
@onBottomReached={{this.onBottomReached}} @addressableAs={{this.addressableAs}}
@disabled={{this.disabled}}>
<:selected-item as |selectedItem|>
{{selectedItem}}
</:selected-item>
Expand All @@ -32,6 +33,7 @@ const defaultArgs = {
loading: false,
loadingMore: false,
borderless: false,
disabled: false,
placeholder: 'My placeholder',
searchPlaceholder: 'My search placeholder',
addressableAs: undefined,
Expand Down Expand Up @@ -91,6 +93,16 @@ export default {
},
control: { type: 'boolean' }
},
disabled: {
description: 'Disable the component: the dropdown cannot be opened',
table: {
type: {
summary: 'boolean'
},
defaultValue: { summary: 'false' }
},
control: { type: 'boolean' }
},
feedbackMessage: {
description: 'A success, warning or error message that will be displayed below the input-group.',
table: {
Expand Down Expand Up @@ -194,10 +206,41 @@ export default {
}
};

const WithRowNamedBlockTemplate = (args) => ({
template: hbs`
<div style="display: flex; justify-content: center; background-color: white; border-radius: 4px">
<OSS::PowerSelect class='padding-sm' @selectedItems={{this.selectedItems}} @items={{this.items}}
@onSearch={{this.onSearch}} @onChange={{this.onChange}} @placeholder={{this.placeholder}}
@searchPlaceholder={{this.searchPlaceholder}}>
<:selected-item as |selectedItem|>
{{selectedItem}}
</:selected-item>
<:row as |item Option|>
<Option @title={{item}} />
</:row>
</OSS::PowerSelect>
</div>
`,
context: args
});

export const Default = {};

export const WithoutSelectedItem = {
args: {
selectedItems: []
}
};

export const WithRowNamedBlock = {
render: WithRowNamedBlockTemplate,
args: {
items: [...FAKE_ITEMS, ...FAKE_SELECTED_ITEMS]
}
};

export const Disabled = {
args: {
disabled: true
}
};
12 changes: 10 additions & 2 deletions packages/oss-components/src/components/o-s-s/power-select.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { helper } from '@ember/component/helper';
import { assert } from '@ember/debug';
import { action } from '@ember/object';
import { scheduleOnce } from '@ember/runloop';
Expand All @@ -19,13 +20,18 @@ interface OSSPowerSelectArgs extends BaseDropdownArgs {
onSearch?: (keyword: string) => void;
onBottomReached?: () => void;
borderless?: boolean;
disabled?: boolean;
}

const DEFAULT_PLACEHOLDER = 'Select an item';

export default class OSSPowerSelect extends BaseDropdown<OSSPowerSelectArgs> {
cleanupDrodpownAutoplacement?: () => void;

isSelected = helper((_, { item }: { item: any }): boolean => {
return (this.args.selectedItems ?? []).includes(item);
});

get placeholder(): string {
return this.args.placeholder ?? DEFAULT_PLACEHOLDER;
}
Expand All @@ -41,9 +47,9 @@ export default class OSSPowerSelect extends BaseDropdown<OSSPowerSelectArgs> {
}

@action
ensureBlockPresence(hasSelectedItem: boolean, hasOptionItem: boolean): void | never {
ensureBlockPresence(hasSelectedItem: boolean, hasOptionItem: boolean, hasRow: boolean): void | never {
assert(`[component][OSS::PowerSelect] You must pass selected-item named block`, hasSelectedItem);
assert(`[component][OSS::PowerSelect] You must pass option-item named block`, hasOptionItem);
assert(`[component][OSS::PowerSelect] You must pass option-item or row named block`, hasOptionItem || hasRow);
}

@action
Expand All @@ -62,6 +68,8 @@ export default class OSSPowerSelect extends BaseDropdown<OSSPowerSelectArgs> {

@action
toggleDropdown(event: MouseEvent): void {
if (this.args.disabled) return;

@phndiaye phndiaye Dec 3, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In some PowerSelects, we have rules like:

  • if more than 3 items, only display one chip saying " items selected" (for example ("4 countries selected")
Screenshot 2026-12-03 at 16 11 57

in that case, we kinda rely on the dropdown to see what's currently selected.

If coupled with that new rule, it means users are blocked with only the <n> items selected without knowing what 😅


super.toggleDropdown(event);

if (!this.isOpen) {
Expand Down
75 changes: 56 additions & 19 deletions packages/oss-components/src/components/o-s-s/select.hbs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<div
class={{this.classNames}}
data-toggle="oss-dropdown"
{{did-insert (fn this.ensureBlockPresence (has-block "option"))}}
{{did-insert this.registerContainer}}
{{will-destroy this.disconnectObserver}}
...attributes
Expand Down Expand Up @@ -47,17 +46,36 @@
{{on "click" this.noop}}
>
<:option as |item index|>
<div
class="item-wrapper fx-row fx-xalign-center fx-malign-space-between {{if (eq @value item) 'selected'}}"
>
{{#if (has-block "option")}}
{{#if (has-block "row")}}
{{yield
item
(component
"o-s-s/infinite-select/option"
selectionType="single"
selected=(this.isSelected item=item)
onSelect=(fn this.onSelect item)
)
index
to="row"
}}
{{else if (has-block "option")}}
<div
class="item-wrapper fx-row fx-xalign-center fx-malign-space-between
{{if (this.isSelected item=item) 'selected'}}"
>
{{yield item index to="option"}}
{{/if}}

{{#if (eq @value item)}}
<OSS::Icon @icon="fa-check" class="font-color-primary-500 padding-right-px-6" />
{{/if}}
</div>
{{#if (this.isSelected item=item)}}
<OSS::Icon @icon="fa-check" class="font-color-primary-500 padding-right-px-6" />
{{/if}}
</div>
{{else}}
<OSS::InfiniteSelect::Option
@title={{concat (get item this.targetValue)}}
@selected={{this.isSelected item=item}}
@onSelect={{fn this.onSelect item}}
/>
{{/if}}
</:option>
<:empty-state>
{{yield to="empty-state"}}
Expand All @@ -78,17 +96,36 @@
{{on "click" this.noop}}
>
<:option as |item index|>
<div
class="item-wrapper fx-row fx-xalign-center fx-malign-space-between {{if (eq @value item) 'selected'}}"
>
{{#if (has-block "option")}}
{{#if (has-block "row")}}
{{yield
item
(component
"o-s-s/infinite-select/option"
selectionType="single"
selected=(this.isSelected item=item)
onSelect=(fn this.onSelect item)
)
index
to="row"
}}
{{else if (has-block "option")}}
<div
class="item-wrapper fx-row fx-xalign-center fx-malign-space-between
{{if (this.isSelected item=item) 'selected'}}"
>
{{yield item index to="option"}}
{{/if}}

{{#if (eq @value item)}}
<OSS::Icon @icon="fa-check" class="font-color-primary-500 padding-right-px-6" />
{{/if}}
</div>
{{#if (this.isSelected item=item)}}
<OSS::Icon @icon="fa-check" class="font-color-primary-500 padding-right-px-6" />
{{/if}}
</div>
{{else}}
<OSS::InfiniteSelect::Option
@title={{concat (get item this.targetValue)}}
@selected={{this.isSelected item=item}}
@onSelect={{fn this.onSelect item}}
/>
{{/if}}
</:option>
</OSS::InfiniteSelect>
{{/if}}
Expand Down
Loading
Loading