plain-solutions-gmbh / kirby-form-block-suite

This form plugin for Kirby offers you maximum flexibility and usability. It can be used as a block anywhere you needed. This repository replaces the obsolete version 2.0.
Other
38 stars 11 forks source link

add aria-labelledby attribute to fields #18

Closed 34N0 closed 1 year ago

34N0 commented 1 year ago

Hey!

As of now the aria-labelledby (https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-labelledby) attribute is not added to the fields.

I implemented the proof of concept like this:

Add the attribute to the field:

snippets/blocks/formfields/input.php:

<input
    ...
    aria-labelledby="<?= "label" . $formfield->id() ?>"
    <?= $formfield->autofill(true) ?>
    <?= $formfield->required('attr') ?>
    <?= $formfield->ariaAttr() ?>
/>

And then add the id to the label:

snippets/blocks/formtemplates/fields.php:

<label id="<?= "label" . $field->id() ?>" ...>

To fully support it should be added to the hidden field as well which could be achieved by using the function:

$form->honeypotId()

The clean implementation would probably be in the ariaAttr() function in the FormField class.

What do you think? How would you like it to be implemented? I would be open to contribute by creating a pr :smile:

plain-solutions-gmbh commented 1 year ago

Hm. Can this also be achieved with the for attribute?

34N0 commented 1 year ago

AFAIK the for is used to explicitally define the relationship between the elements and is used by the html5 validation and some js validation libraries. It might be that some accessibility tools like screen readers use the field as a fall back if aria-labelledby is not set.

But setting the aria-labelledby is general best practice.

plain-solutions-gmbh commented 1 year ago

Okay. It's implemented in version 3.4.8. I put aria-hidden on honeypot-input too. Thanks for you support. Send me a pm for your free license as thanks for your improvement.