Skip to content

Commit

Permalink
Merge pull request #2502 from hashicorp/alex-ju/super-select-custom-r…
Browse files Browse the repository at this point in the history
…esult-count-message

`SuperSelect::Multiple` - allow custom result count message
  • Loading branch information
alex-ju authored Oct 14, 2024
2 parents 4030b10 + f502329 commit 7142a93
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/spotty-boxes-do.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hashicorp/design-system-components": minor
---

`SuperSelect::Multiple` - Added `@resultCountMessage` argument to enable override
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ export default class HdsFormSuperSelectMultipleBase extends Component<HdsFormSup
}

get resultCountMessage(): string {
return `${this.selectedCount} selected of ${this.optionsCount} total`;
return (
this.args.resultCountMessage ||
`${this.selectedCount} selected of ${this.optionsCount} total`
);
}

@action calculatePosition(
Expand Down
19 changes: 19 additions & 0 deletions showcase/app/templates/components/form/super-select.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,25 @@
</SF.Item>
</Shw::Flex>

<Shw::Text::H4>Custom result count message</Shw::Text::H4>

<Shw::Flex {{style padding-bottom="15em"}} @direction="row" as |SF|>
<SF.Item>
<Hds::Form::SuperSelect::Multiple::Base
@resultCountMessage="{{@model.PLACES_OPTIONS.length}} total"
@onChange={{fn (mut @model.SELECTED_PLACES_OPTIONS)}}
@options={{@model.PLACES_OPTIONS}}
@selected={{@model.SELECTED_PLACES_OPTIONS}}
@initiallyOpened={{true}}
@verticalPosition="below"
@ariaLabel="Label"
as |option|
>
{{option}}
</Hds::Form::SuperSelect::Multiple::Base>
</SF.Item>
</Shw::Flex>

<Shw::Divider />

<Shw::Text::H2>Form::SuperSelect::Multiple::Field</Shw::Text::H2>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,25 @@ module(
assert.dom('.hds-form-super-select__after-options').doesNotExist();
});

test('it should render the default after options block with custom result count message when `@resultCountMessage` exists', async function (assert) {
setOptionsData(this);
await render(
hbs`<Hds::Form::SuperSelect::Multiple::Base @onChange={{this.NOOP}} @options={{this.OPTIONS}} @resultCountMessage="custom result count message" as |option|>{{option}}</Hds::Form::SuperSelect::Multiple::Base>`
);
await click('.hds-form-super-select .ember-basic-dropdown-trigger');
assert
.dom(
'.hds-form-super-select__after-options .hds-form-super-select__result-count'
)
.hasText('custom result count message');
assert
.dom('.hds-form-super-select__after-options .hds-button')
.hasText('Show selected');
assert
.dom('.hds-form-super-select__after-options .hds-button')
.doesNotHaveTextContaining('Clear selected');
});

// MATCH TRIGGER WIDTH

test('`@matchTriggerWidth` should be true by default', async function (assert) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ The default values of some [ember-power-select](https://ember-power-select.com/d
<C.Property @name="afterOptionsContent" @type="string" @default="resultCountMessage">
Sets the content of the default `afterOptions` component overriding the default content.
</C.Property>
<C.Property @name="resultCountMessage" @type="string">
Overrides the default result count message. The default message follows this pattern: X selected of Y total.
</C.Property>
<C.Property @name="closeOnSelect" @type="boolean" @default="false">
Defaults to true instead for `SuperSelect::Single`.
</C.Property>
Expand Down

0 comments on commit 7142a93

Please sign in to comment.