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 cd34721
Show file tree
Hide file tree
Showing 8 changed files with 5 additions and 49 deletions.
6 changes: 0 additions & 6 deletions components/combobox/src/auro-combobox.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,12 +382,6 @@ export class AuroCombobox extends LitElement {
this.menu.addEventListener('auroMenu-selectValueFailure', () => {
this.optionSelected = undefined;
});

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

/**
Expand Down
1 change: 0 additions & 1 deletion components/menu/demo/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ The auro-menu element provides users a way to select from a list of options.
| `auroMenu-customEventFired` | `CustomEvent<any>` | Notifies that a custom event has been fired. |
| `auroMenu-loadingChange` | `CustomEvent<{ loading: boolean; hasLoadingPlaceholder: boolean; }>` | Notifies when the loading attribute is changed. |
| `auroMenu-selectValueFailure` | `CustomEvent<any>` | Notifies that a an attempt to select a menuoption by matching a value has failed. |
| `auroMenu-selectValueReset` | `CustomEvent<any>` | Notifies that the component value has been reset. |
| `auroMenu-selectedOption` | `CustomEvent<any>` | Notifies that a new menuoption selection has been made. |

## Slots
Expand Down
1 change: 0 additions & 1 deletion components/menu/docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ The auro-menu element provides users a way to select from a list of options.
| `auroMenu-customEventFired` | `CustomEvent<any>` | Notifies that a custom event has been fired. |
| `auroMenu-loadingChange` | `CustomEvent<{ loading: boolean; hasLoadingPlaceholder: boolean; }>` | Notifies when the loading attribute is changed. |
| `auroMenu-selectValueFailure` | `CustomEvent<any>` | Notifies that a an attempt to select a menuoption by matching a value has failed. |
| `auroMenu-selectValueReset` | `CustomEvent<any>` | Notifies that the component value has been reset. |
| `auroMenu-selectedOption` | `CustomEvent<any>` | Notifies that a new menuoption selection has been made. |

## Slots
Expand Down
7 changes: 0 additions & 7 deletions components/menu/src/auro-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import AuroLibraryRuntimeUtils from '@aurodesignsystem/auro-library/scripts/util
* @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-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 Expand Up @@ -436,12 +435,6 @@ export class AuroMenu extends LitElement {
}
} else {
this.resetOptionsStates();

this.dispatchEvent(new CustomEvent('auroMenu-selectValueReset', {
bubbles: true,
cancelable: false,
composed: true,
}));
}
}

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 cd34721

Please sign in to comment.