Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix/issue-434/filters-reset #436

Merged
merged 3 commits into from
Jul 17, 2024
Merged
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
2 changes: 1 addition & 1 deletion src/components/filters/_filters.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
</button>{{/if}}
<div class="nsw-filters__item-content">
<label class="nsw-form__label{{#if collapsed}} sr-only{{/if}}" for="{{select.id}}-{{filters-id}}">{{select.name}}</label>{{#if multiple}}
<div class="nsw-multi-select js-multi-select" data-no-select-text="Select savings programs" data-multi-select-text="{n} items selected" data-n-multi-select="2">{{/if}}
<div class="nsw-multi-select js-multi-select" data-select-text="Select regions" data-multi-select-text="{n} regions selected" data-n-multi-select="2">{{/if}}
<select{{#unless multiple}} class="nsw-form__select"{{/unless}} name="{{select.id}}-{{filters-id}}" id="{{select.id}}-{{filters-id}}"{{#if helper-text}} aria-describedby="{{#if helper-text}}{{select.id}}-{{filters-id}}-helper-text{{/if}}"{{/if}}{{#if error-text}} aria-invalid="true"{{/if}}{{#if multiple}} multiple{{/if}}>{{#unless multiple}}<option value="">Please select</option>{{/unless}}
{{#each select.list}}
<option value="{{this}}">{{this}}</option>
Expand Down
17 changes: 15 additions & 2 deletions src/components/filters/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class Filters {
this.showMoreContent = this.element.querySelectorAll(`.${this.prefix}${this.allClass}`)
this.showMoreButtons = this.element.querySelectorAll(`.${this.prefix}${this.moreClass}`)
this.focusableElements = 'a[href]:not([disabled]), button:not([disabled]), textarea:not([disabled]), input[type="text"]:not([disabled]), input[type="radio"]:not([disabled]), input[type="checkbox"]:not([disabled]), select:not([disabled])'
// Get default selected option
this.selectedOption = this.element.querySelector('option[selected]')
// Accordion arrays
this.buttons = []
this.content = []
Expand Down Expand Up @@ -208,11 +210,22 @@ class Filters {
if (this.options.length > 0) {
this.options.forEach((input) => {
const option = input
if (option.type === 'text' || option.type === 'select-one') {
if (option.type === 'text') {
option.value = ''
} else if (option.type === 'select-one') {
if (this.selectedOption) {
option.selectedIndex = this.selectedOption.index
} else {
option.selectedIndex = 0
}
} else if (option.type === 'checkbox') {
if (option.defaultChecked) {
option.checked = true
} else {
option.checked = false
}
} else if (!option.parentElement.classList.contains('js-multi-select__option')) {
option.value = false
option.checked = false
}
})
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/select/test.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ model:
</button>
<div class="nsw-filters__item-content">
<label class="nsw-form__label sr-only" for="filters-instant-regions-8">Region</label>
<div class="nsw-multi-select js-multi-select" data-no-select-text="Select savings programs" data-multi-select-text="{n} items selected" data-n-multi-select="2">
<div class="nsw-multi-select js-multi-select" data-select-text="Select regions" data-multi-select-text="{n} regions selected" data-n-multi-select="2">
<select name="filters-instant-regions-8" id="filters-instant-regions-8" multiple>
<option value="Central Coast" selected="true">Central Coast</option>
<option value="Central West &amp; Orana">Central West &amp; Orana</option>
Expand Down