Merge pull request #135 from shoelace-style/konnorrogers/dropdown-and-input-fixes

dropdown and input fixes
This commit is contained in:
Cory LaViska
2024-06-18 18:13:50 -04:00
committed by GitHub
2 changed files with 14 additions and 7 deletions

View File

@@ -295,9 +295,9 @@ export default class WaDropdown extends WebAwesomeElement {
// Either the tag hasn't registered, or it hasn't rendered.
// So, wait for the tag to register, and then try again.
if (target === undefined) {
if (target === undefined || target === null) {
customElements.whenDefined(tagName).then(async () => {
await (target as WaButton | WaIconButton).updateComplete;
await (accessibleTrigger as WaButton | WaIconButton).updateComplete;
this.updateAccessibleTrigger();
});

View File

@@ -260,16 +260,23 @@ export default class WaInput extends WebAwesomeFormAssociatedElement {
return;
}
const button = [...form.elements].find((el: HTMLButtonElement) => el.type === 'submit' && !el.disabled) as
| undefined
| HTMLButtonElement
| WaButton;
const formElements = [...form.elements];
if (!button) {
// If we're the only formElement, we submit like a native input.
if (formElements.length === 1) {
form.requestSubmit(null);
return;
}
const button = formElements.find(
(el: HTMLButtonElement) => el.type === 'submit' && !el.matches(':disabled')
) as undefined | HTMLButtonElement | WaButton;
// No button found, don't submit.
if (!button) {
return;
}
if (button.tagName.toLowerCase() === 'button') {
form.requestSubmit(button);
} else {