index.ts 885 B

12345678910111213141516171819202122232425262728
  1. // Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
  2. import { FormKitNode } from '@formkit/core'
  3. import createInput from '@shared/form/core/createInput'
  4. import extendSchemaDefinition from '@shared/form/utils/extendSchemaDefinition'
  5. import FieldEditorWrapper from './FieldEditorWrapper.vue'
  6. const addAriaLabel = (node: FormKitNode) => {
  7. const { props } = node
  8. // Specification doesn't allow accessing non-labeled elements, which Editor is (<div />)
  9. // (https://html.spec.whatwg.org/multipage/forms.html#category-label)
  10. // So, editor has `aria-labelledby` attribute and a label with the same ID
  11. extendSchemaDefinition(node, 'label', {
  12. attrs: {
  13. id: props.id,
  14. },
  15. })
  16. }
  17. const fieldDefinition = createInput(FieldEditorWrapper, [], {
  18. features: [addAriaLabel],
  19. })
  20. export default {
  21. fieldType: 'editor',
  22. definition: fieldDefinition,
  23. }