Due to how vue attribute binding works, all dialog buttons have the data-mdc-dialog-button-default attribute. The default button has it set to true, and other buttons have it set to false. However, the querySelector functions ignores the value of the attribute and returns the first element that have it, effectively always returning the first button.
Description
The
isDefault
prop on themcw-dialog-button
doesn’t really work.Steps to reproduce
Create the dialog with the text field, and make sure the
isDefault
prop is set on the second dialog button, such as below:Add some log to the
accept
functionOpen the dialog and focus the text field
Press the Enter key
Expected result
accept
function is called (there is a log)Actual result
accept
function is NOT called (there is no log)Analysis
It looks like the issue is caused by the implementation of getting the default button element:
https://github.com/pgbross/vue-material-adapter/blob/8058d8b06b805de3e66f81b6eeb78646d599ec7c/src/dialog/dialog.js#L153-L155
Due to how vue attribute binding works, all dialog buttons have the
data-mdc-dialog-button-default
attribute. The default button has it set totrue
, and other buttons have it set tofalse
. However, thequerySelector
functions ignores the value of the attribute and returns the first element that have it, effectively always returning the first button.Workaround
Make the default button the first in the dialog.