Skip to content

Commit

Permalink
perf: update handling of invalid values in select
Browse files Browse the repository at this point in the history
BREAKING CHANGE: The auroMenu-selectValueReset is now deprecated as it is no longer needed.
  • Loading branch information
jordanjones243 committed Jan 7, 2025
1 parent 1861de9 commit e69fb46
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 38 deletions.
4 changes: 1 addition & 3 deletions components/combobox/src/auro-combobox.js
Original file line number Diff line number Diff line change
Expand Up @@ -384,9 +384,7 @@ export class AuroCombobox extends LitElement {
});

this.menu.addEventListener('auroMenu-selectValueReset', () => {
this.optionSelected = undefined;
this.value = undefined;
this.validation.validate(this);
this.reset();
});
}

Expand Down
2 changes: 1 addition & 1 deletion components/menu/src/auro-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import AuroLibraryRuntimeUtils from '@aurodesignsystem/auro-library/scripts/util
* @event auroMenu-selectedOption - Notifies that a new menuoption selection has been made.
* @event auroMenu-activatedOption - Notifies that a menuoption has been made `active`.
* @event auroMenu-selectValueFailure - Notifies that a an attempt to select a menuoption by matching a value has failed.
* @event auroMenu-customEventFired - Notifies that a custom event has been fired.
* @event auroMenu-selectValueReset - Notifies that the component value has been reset.
* @event auroMenu-customEventFired - Notifies that a custom event has been fired.
* @event auroMenu-loadingChange - Notifies when the loading attribute is changed.
* @slot loadingText - Text to show while loading attribute is set
* @slot loadingIcon - Icon to show while loading attribute is set
Expand Down
1 change: 0 additions & 1 deletion components/select/apiExamples/value.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<auro-button id="validValueExampleBtn">Set Value to Valid Option</auro-button>
<auro-button id="invalidValueExampleBtn">Set Value to Invalid Option</auro-button>
<auro-button id="undefinedValueExampleBtn">Set Value to Undefined</auro-button>
<br/><br/>
<auro-select id="valueExample" value="price">
<span slot="label">Name</span>
Expand Down
8 changes: 2 additions & 6 deletions components/select/apiExamples/value.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,9 @@ export function valueExample() {

document.querySelector('#validValueExampleBtn').addEventListener('click', () => {
valueExample.value = 'arrival';
})
});

document.querySelector('#invalidValueExampleBtn').addEventListener('click', () => {
valueExample.value = 'flight course';
})

document.querySelector('#undefinedValueExampleBtn').addEventListener('click', () => {
valueExample.value = undefined;
})
});
}
10 changes: 2 additions & 8 deletions components/select/demo/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ To pre-set the value of auro-select on load, use the `value` property. The `sele
<!-- The below content is automatically added from ./../apiExamples/value.html -->
<auro-button id="validValueExampleBtn">Set Value to Valid Option</auro-button>
<auro-button id="invalidValueExampleBtn">Set Value to Invalid Option</auro-button>
<auro-button id="undefinedValueExampleBtn">Set Value to Undefined</auro-button>
<br/><br/>
<auro-select id="valueExample" value="price">
<span slot="label">Name</span>
Expand All @@ -134,7 +133,6 @@ To pre-set the value of auro-select on load, use the `value` property. The `sele
```html
<auro-button id="validValueExampleBtn">Set Value to Valid Option</auro-button>
<auro-button id="invalidValueExampleBtn">Set Value to Invalid Option</auro-button>
<auro-button id="undefinedValueExampleBtn">Set Value to Undefined</auro-button>
<br/><br/>
<auro-select id="valueExample" value="price">
<span slot="label">Name</span>
Expand All @@ -158,15 +156,11 @@ export function valueExample() {

document.querySelector('#validValueExampleBtn').addEventListener('click', () => {
valueExample.value = 'arrival';
})
});

document.querySelector('#invalidValueExampleBtn').addEventListener('click', () => {
valueExample.value = 'flight course';
})

document.querySelector('#undefinedValueExampleBtn').addEventListener('click', () => {
valueExample.value = undefined;
})
});
}
```
<!-- AURO-GENERATED-CONTENT:END -->
Expand Down
20 changes: 1 addition & 19 deletions components/select/src/auro-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,26 +277,8 @@ export class AuroSelect extends LitElement {
* with `auro-select.value`.
*/
this.menu.addEventListener('auroMenu-selectValueFailure', () => {
this.menu.optionSelected = undefined;
this.optionSelected = this.menu.optionSelected;

this.validity = 'patternMismatch';

// Capitalizes the first letter of each word in this.value string
const valueStr = this.value.replace(/(^\w{1})|(\s+\w{1})/gu, (letter) => letter.toUpperCase());

// Pass the new string to the trigger content
this.updateDisplayedValue(valueStr);
});

this.menu.addEventListener('auroMenu-selectValueReset', () => {
// set the trigger content back to the placeholder
this.reset();
this.updateDisplayedValue(this.placeholder);

this.optionSelected = undefined;
this.value = undefined;

this.validation.validate(this);
});
}

Expand Down

0 comments on commit e69fb46

Please sign in to comment.