material-web
material-web copied to clipboard
Button type submit
I'm suprised this hasn't seemed to have come up, but you should be able to pass down button types like submit and reset. <mdc-button type="submit" ... />
Related #205
Ugly workaround: <mwc-button onclick="event.target.closest('form').submit()">.
I just found out that this workaround is bad if you have submit event listeners. You would need to use https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement/requestSubmit which is not supported in enough browsers. So I think this should be prioritized because implementation doesn't seem that hard and it's really annoying. The only workaround is probably to use the onclick for submitting which probably doesn't work when pressing enter or so. This also doesn't do form validation.
Any news on this?
Looking at the new implementation of the button component in https://github.com/material-components/material-web/blob/master/button/lib/button.ts
I noticed that type prop was missing again, is there a particular reason?
I think it makes sense to add type when we update components to be Form Associated Custom Elements (FACE)
Brilliant thank you! I noticed it's resolved https://github.com/material-components/material-web/blob/main/button/lib/button.ts#L76