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

SubmitEvent.submitter should be HTMLButtonElement instead of HTMLElement #7038

Closed
poacher2k opened this issue Sep 8, 2021 · 3 comments
Closed

Comments

@poacher2k
Copy link

Hi!

Currently submitter in the SubmitEvent interface is typed as a HTMLElement, but an element of this type has no value property by default, and furthermore the submitter can only ever be of type HTMLButtonElement, HTMLInputElement or null.

Would this not be more correct?

type SubmitButton = HTMLButtonElement | HTMLInputElement;

interface SubmitEvent : Event {
  constructor(DOMString type, optional SubmitEventInit eventInitDict = {});

  readonly attribute SubmitButton? submitter;
};

dictionary SubmitEventInit : EventInit {
  SubmitButton? submitter = null;
};

Link to spec: https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#the-submitevent-interface:submiteventinit

@domenic
Copy link
Member

domenic commented Sep 8, 2021

I don't think it would be "more correct"; HTMLElement is correct, in that everything returned by that is a HTMLElement or null. In general we avoid using unions for return types in the way you're suggesting, since it makes spec maintenance harder. (For example, we would then need to update it if we ever solve WICG/webcomponents#814.)

I'll close this since I don't think we should change the spec here, but I'm happy to continue discussing in the closed thread.

Also I have no idea what language you're using in your code example; it doesn't appear in the spec.

@domenic domenic closed this as completed Sep 8, 2021
@poacher2k
Copy link
Author

Thank you for your detailed response and patience! I hope my lack of in-depth knowledge about this is apparent.

It makes sense to avoid unions, and in that case I would still suggest to make the return type solely a HTMLButtonElement rather than a HTMLElement. Do I understand it correctly that of the main reasons you would be interested in the submitter, is to access its value and/or action - both which are attributes that a HTMLElement lack?

The practical reason for my proposal - which I know perhaps isn't really any concern of whatwg - is that the whatwg spec is the source of truth for the dom.generated.d.ts-file by the DefinitelyTyped-project, which in turn serves as the source of truth for all TypeScript-projects, and for the IntelliSense provided in eg. Visual Studio Code.

As of now, if you want to access event.submitter.value or event.submitter.action from a SubmitEvent, you will have to cast it to a HTMLButtonElement or HTMLInputElement first.

The language in the code example is IDL with a coating of TypeScript on the first line :)

@poacher2k poacher2k changed the title SubmitEvent.submitter should be HTMLButtonElement | HTMLInputElement instead of HTMLElement SubmitEvent.submitter should be HTMLButtonElement instead of HTMLElement Sep 8, 2021
@domenic
Copy link
Member

domenic commented Sep 8, 2021

Yeah, I think this is best addressed on the TypeScript side.

Using HTMLButtonElement would be incorrect, because then the spec would not be allowed to set it to <input type=submit> elements. So we cannot do that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants