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

♿️ aria(checkbox/radio): added aria attributes for accessibility features #20

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions assets/js/public/form-field-unique.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,16 @@
const iname = input.prop( 'name' );
const curid = input.prop( 'id' );
const forid = form.data( 'id' );
const radioname = label.find( '.forminator-radio-option' );
const optionid = curid + '-option-' + forid;
const uname = iname + '-' + forid;
const unqid = curid + '-' + forid;

input.prop( 'id', unqid );
input.prop( 'name', uname );
label.prop( 'for', unqid );
input.attr( 'aria-labelledby', optionid );
radioname.prop( 'id', optionid );

});
}
Expand All @@ -108,10 +112,14 @@
const label = input.parent();
const curid = input.prop( 'id' );
const forid = form.data( 'id' );
const checkboxname = label.find( '.forminator-checkbox-option' );
const optionid = curid + '-option-' + forid;
const unqid = curid + '-' + forid;

input.prop( 'id', unqid );
label.prop( 'for', unqid );
input.attr( 'aria-labelledby', optionid );
checkboxname.prop( 'id', optionid );

});
}
Expand Down
6 changes: 3 additions & 3 deletions templates/form-elements/field-checkbox.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
id="checkbox-option-1"
/>
<span aria-hidden="true"></span>
<span>Design</span>
<span class="forminator-checkbox-option">Design</span>
</label>

<label
Expand All @@ -25,7 +25,7 @@
id="checkbox-option-2"
/>
<span aria-hidden="true"></span>
<span>Development</span>
<span class="forminator-checkbox-option">Development</span>
</label>

<label
Expand All @@ -38,7 +38,7 @@
id="checkbox-option-3"
/>
<span aria-hidden="true"></span>
<span>Technical Support</span>
<span class="forminator-checkbox-option">Technical Support</span>
</label>

<span class="forminator-error-message" aria-hidden="true">This field is required.</span>
Expand Down
6 changes: 3 additions & 3 deletions templates/form-elements/field-radio.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
id="radio-option-1"
/>
<span aria-hidden="true"></span>
<span>$100 - $500 USD</span>
<span class="forminator-radio-option">$100 - $500 USD</span>
</label>

<label
Expand All @@ -27,7 +27,7 @@
id="radio-option-2"
/>
<span aria-hidden="true"></span>
<span>$501 - $1000 USD</span>
<span class="forminator-radio-option">$501 - $1000 USD</span>
</label>

<label
Expand All @@ -41,7 +41,7 @@
id="radio-option-3"
/>
<span aria-hidden="true"></span>
<span>$1001 or more USD</span>
<span class="forminator-radio-option">$1001 or more USD</span>
</label>

<span class="forminator-error-message">This field is required.</span>
Expand Down