Skip to content

feat: add support for required attribute #53

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

Open
wants to merge 3 commits into
base: trunk
Choose a base branch
from

Conversation

frosso
Copy link

@frosso frosso commented Jun 28, 2024

This pull request includes a

  • Bug fix
  • New feature
  • Translation

Adding support for the required attribute, so that it can be read by Screen Readers.
Porting of the changes from woocommerce/woocommerce#48371

I added examples in the docs/accessibility-testing/ directory for how to instantiate a "required" select.

The following changes were made

  • Added aria-required to the combobox and textbox elements, for better support w/ Firefox, Chrome, etc.
  • required attribute can be set via option on instantiation, or via required attribute on the original select element

I noticed that the assets are committed compiled in the repo - so I built them as well.

Screenshot 2024-06-28 at 12 03 21 PM

Copy link

@naman03malhotra naman03malhotra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for making this change and making this lib more accessible. I've left some comments


this.container = container;

if (isRequired) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a PR under review that drops select2

woocommerce/woocommerce#48731

So these changes might not be required.


this.container = container;

if (isRequired) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same for this file ^

woocommerce/woocommerce#48731

@@ -4420,7 +4429,7 @@ S2.define('select2/dropdown/attachBody',[

if (newDirection == 'above' ||
(isCurrentlyAbove && newDirection !== 'below')) {
css.top = container.top - parentOffset.top - dropdown.height;
css.top = container.top - dropdown.height;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious, why we had to make this change? and that too only for Select2 lib and not SelectWoo.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been auto-compiled and bundled within here because of changes from a previous PR that didn't get compiled: https://github.com/woocommerce/selectWoo/pull/49/files

<select name="required_option" id="required_option" class="country_to_state country_select "><option value="">Select a country&hellip; (required)</option><option value="AX" >&#197;land Islands</option><option value="AF" >Afghanistan</option><option value="AL" >Albania</option><option value="DZ" >Algeria</option><option value="AS" >American Samoa</option><option value="AD" >Andorra</option><option value="AO" >Angola</option><option value="AI" >Anguilla</option><option value="AQ" >Antarctica</option><option value="EH" >Western Sahara</option><option value="YE" >Yemen</option><option value="ZM" >Zambia</option><option value="ZW" >Zimbabwe</option></select>

<script>
$( '#not_required' ).select2();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably we also should use .selectWoo signature which is consistent with what we are using in the core.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Every other HTML file in the sample directory uses select2, so I thought I'd be consistent here.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though we still support select2's signature, we have officially removed it from our repo, woocommerce/woocommerce#48731. Maybe as part of another Issue, we should keep the samples consistent.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, that sounds fine!

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

Successfully merging this pull request may close these issues.

2 participants