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

Formio Builder configuration with accessibility #560

Open
DonAmit197 opened this issue Mar 18, 2024 · 3 comments
Open

Formio Builder configuration with accessibility #560

DonAmit197 opened this issue Mar 18, 2024 · 3 comments

Comments

@DonAmit197
Copy link

Hi,
I'm using formio-react to build a custom builder. I have concern about integrating accessibility configuration in the builder. I understand the fields are drag and drop using Dragula. Is there any chance for any addition of using a 'Tab' key for adding fields into the builder?

Thanks in advance.

@lane-formio
Copy link
Contributor

This can actually be done on a per-form basis by adding keyboardBuilder = true as a custom property in form settings. The related PRs can be found here and [here] (formio/formio.js#5152).

image

@DonAmit197
Copy link
Author

@lane-formio , I have tried the way you suggested but it doesn't suffice my requirement, instead what I did I have added a tabindex="0" to the formcomponent

const sideBarBtns = document.querySelectorAll(".formcomponent.drag-copy");
  sideBarBtns.forEach((btn) => {
    //console.log(btn);
    btn.setAttribute("tabIndex", "0");
    btn.addEventListener("keydown", function (e) {
      performOnEnter(e);
    });
  });

and the tabIndex works fine. Now my intension is to open the Edit modal screen on "keydown" event. To make this happen I feel that I have to extend the WebformBuilder class. I'm importing the formiojs by var _formiojs = require("formiojs"); There I can see are few methods like initDragula, onDrop. Could you please suggest which method I should trigger?

Thanks in advance

@lane-formio lane-formio reopened this Mar 22, 2024
@DonAmit197
Copy link
Author

DonAmit197 commented Mar 26, 2024

At least got some success to open the edit modal on hitting the Enter key. Created a new method

WebformBuilder.default.prototype.addKeyBoardEvent = function () {
  console.log('ADDKEYB', this);
  this.refs['sidebar-component'].forEach((component) => {
    component.setAttribute('tabindex', '0');
    this.addEventListener(component, 'keydown', (event) => {
      if (event.keyCode === 13) {
        this.addNewComponent(component);
      }
    });
  });

  const componentEdit = this.componentEdit;
  const _self = this;
  if (componentEdit) {
    const removeBtn = componentEdit.querySelector('[ref="removeButton"]');
    removeBtn.addEventListener('keydown', (event) => {
      if (event.keyCode === 13) {
        console.log(this);
        //this.saved = true;
        //this.editForm.detach();
        //this.removeComponent();
        _self.dialog.close();
        //this.highlightInvalidComponents();
      }
    });
  }
};

called the method inside

WebformBuilder.default.prototype.initDragula = function () {
 this.addKeyBoardEvent();
}

But I can observe (however I can understand that I'm doing wrong somewhere) that on hitting the "Enter" key on the "Save" button it's not working. Throwing an error "Cannot read properties of null (reading 'component')" . Any idea or feedback on this? Appreciate any help. Thanks.

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

No branches or pull requests

2 participants