diff --git a/src/boot/dataCy.js b/src/boot/dataCy.js new file mode 100644 index 000000000..18f200ae6 --- /dev/null +++ b/src/boot/dataCy.js @@ -0,0 +1,17 @@ +export default { + mounted: function (el, binding, { ctx }) { + const { innerText, localName } = el; + const { type, attrs } = ctx; + + el.setAttribute( + 'data-cy', + `${attrs?.label ?? innerText}_${type.name.replace('Q', '').toLowerCase()}` + ); + console.error('dataCy', el.getAttribute('data-cy')); + }, + unmounted: function (el) { + if (el._handleKeydown) { + window.removeEventListener('keydown', el._handleKeydown); + } + }, +}; diff --git a/src/boot/quasar.js b/src/boot/quasar.js index 01fe68d8b..f6c6c3331 100644 --- a/src/boot/quasar.js +++ b/src/boot/quasar.js @@ -3,12 +3,14 @@ import qFormMixin from './qformMixin'; import keyShortcut from './keyShortcut'; import useNotify from 'src/composables/useNotify.js'; import { CanceledError } from 'axios'; +import dataCy from './dataCy'; const { notify } = useNotify(); export default boot(({ app }) => { app.mixin(qFormMixin); app.directive('shortcut', keyShortcut); + app.directive('dataCy', dataCy); app.config.errorHandler = (error) => { let message; const response = error.response;