Skip to content

Commit

Permalink
Update multiselect
Browse files Browse the repository at this point in the history
  • Loading branch information
ayangster committed Sep 14, 2023
1 parent 1ed5797 commit f34d4af
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 74 deletions.
4 changes: 2 additions & 2 deletions src/calculator-form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ const HOUSEHOLD_SIZE_OPTIONS: OptionParam[] = [1, 2, 3, 4, 5, 6, 7, 8].map(
// }

export const formTemplate = (
[zip, ownerStatus, projects, householdIncome, taxFiling, householdSize]: Array<string>,
[zip, ownerStatus, householdIncome, taxFiling, householdSize]: Array<string>,
projects: Array<string>,
onSubmit: (e: SubmitEvent) => void,
) => html`
<form @submit=${onSubmit}>
Expand Down Expand Up @@ -145,7 +146,6 @@ export const formTemplate = (
id: 'projects',
options: PROJECT_OPTIONS,
currentValues: projects,
tabIndex: 0,
})}
</label>
</div>
Expand Down
9 changes: 3 additions & 6 deletions src/calculator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ export class RewiringAmericaCalculator extends LitElement {
@property({ type: String, attribute: 'owner-status' })
ownerStatus: OwnerStatus = 'homeowner';

@property({ type: String, attribute: 'projects'})
projects: string = 'heating'
@property({ type: Array, attribute: 'projects'})
projects: string[] = ['heating']

@property({ type: String, attribute: 'household-income' })
householdIncome: string = '0';
Expand Down Expand Up @@ -114,7 +114,6 @@ export class RewiringAmericaCalculator extends LitElement {
task: async ([
zip,
owner_status,
projects,
household_income,
tax_filing,
household_size,
Expand All @@ -126,7 +125,6 @@ export class RewiringAmericaCalculator extends LitElement {
const query = new URLSearchParams({
zip,
owner_status,
projects,
household_income,
tax_filing,
household_size,
Expand All @@ -142,7 +140,6 @@ export class RewiringAmericaCalculator extends LitElement {
args: () => [
this.zip,
this.ownerStatus,
this.projects,
this.householdIncome,
this.taxFiling,
this.householdSize,
Expand All @@ -160,11 +157,11 @@ export class RewiringAmericaCalculator extends LitElement {
[
this.zip,
this.ownerStatus,
this.projects,
this.householdIncome,
this.taxFiling,
this.householdSize,
],
this.projects,
(event: SubmitEvent) => this.submit(event),
)}
</div>
Expand Down
14 changes: 6 additions & 8 deletions src/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,18 @@ export interface SelectParam {
export interface MultiSelectParam {
id: string;
label?: string;
currentValues: string;
currentValues: string[];
options: OptionParam[];
helpText?: string;
placeholder?: string;
maxOptionsVisible?: number;
tabIndex?: number;
}

export const option = ({ label, value }: OptionParam, selected: boolean) =>
html` <option value="${value}" ?selected=${selected}>${label}</option> `;

export const multioption = ({ label, value }: OptionParam, selected: boolean) =>
html` <sl-option value="${value}" ?selected=${selected}>${label}</sl-option> `;
export const multioption = ({ label, value }: OptionParam) =>
html` <sl-option value="${value}" >${label}</sl-option> `;

export const select = ({
id,
Expand Down Expand Up @@ -63,21 +62,20 @@ export const multiselect = ({
helpText,
placeholder,
maxOptionsVisible,
tabIndex,
}: MultiSelectParam) => {
return html`
<div>
<sl-select
id="${id}"
name="${id}"
label="${ifDefined(label)}"
value="${currentValues}"
value="${currentValues.join(' ')}"
help-text="${ifDefined(helpText)}"
placeholder="${ifDefined(placeholder)}"
max-options-visible="${ifDefined(maxOptionsVisible)}"
tabindex="${ifDefined(tabIndex)}"
multiple
>
${options.map(o => multioption(o, o.value === currentValues))}
${options.map(o => multioption(o))}
</sl-select>
<span class="focus"></span>
</div>
Expand Down
Loading

0 comments on commit f34d4af

Please sign in to comment.