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

feat(storefront): BCTHEME-128 Error messages from Write a Review form… #1777

Merged
merged 2 commits into from
Aug 26, 2020
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

## Draft
- Error messages from Write a Review should be announced. [#1777](https://github.com/bigcommerce/cornerstone/pull/1777)
- Fixed issue with missing logo on mobile and tablet. [#1767](https://github.com/bigcommerce/cornerstone/pull/1767)
- Visually hidden cart link read by screen reader. [#1770](https://github.com/bigcommerce/cornerstone/pull/1770)
- Improper heading hierarchy on Cart page. [#1775](https://github.com/bigcommerce/cornerstone/pull/1775)
Expand Down
11 changes: 11 additions & 0 deletions assets/js/theme/product.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export default class Product extends PageManager {

$('body').on('click', '[data-reveal-id="modal-review-form"]', () => {
validator = review.registerValidation(this.context);
this.ariaDescribeReviewInputs($reviewForm);
});

$reviewForm.on('submit', () => {
Expand All @@ -54,6 +55,16 @@ export default class Product extends PageManager {
this.bulkPricingHandler();
}

ariaDescribeReviewInputs($form) {
$form.find('[data-input]').each((_, input) => {
const $input = $(input);
const msgSpanId = `${$input.attr('name')}-msg`;

$input.siblings('span').attr('id', msgSpanId);
$input.attr('aria-describedby', msgSpanId);
});
}

productReviewHandler() {
if (this.url.indexOf('#write_review') !== -1) {
this.$reviewLink.trigger('click');
Expand Down
11 changes: 10 additions & 1 deletion templates/components/common/forms/checkbox.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,16 @@
</label>
{{#if checkboxes}}
{{#each checkboxes}}
<input type="checkbox" value="{{value}}" name="{{name}}" id="{{name}}" data-label="{{label}}" class="form-checkbox" {{#if checked}}checked{{/if}} {{#if private_id}}data-field-type="{{private_id}}"{{/if}}>
<input type="checkbox"
value="{{value}}"
name="{{name}}"
id="{{name}}"
data-input
data-label="{{label}}"
class="form-checkbox"
{{#if checked}}checked{{/if}}
{{#if private_id}}data-field-type="{{private_id}}"{{/if}}
>
<label class="form-label {{class}}" for="{{name}}">{{label}}</label>
{{/each}}
{{/if}}
Expand Down
27 changes: 24 additions & 3 deletions templates/components/common/forms/date.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,42 @@
{{#if required}}<small>{{lang 'common.required' }}</small>{{/if}}</label>
<div class="form-row form-row--third">
<div class="form-field">
<select class="form-select" name="{{month.name}}" id="{{id}}_month" data-label="month" aria-required="{{required}}" {{#if private_id}}data-field-type="{{private_id}}"{{/if}}>
<select class="form-select"
name="{{month.name}}"
id="{{id}}_month"
data-label="month"
data-input
aria-required="{{required}}"
{{#if private_id}}data-field-type="{{private_id}}"{{/if}}
>
{{#each month.items}}
<option {{#if ../month.value '==' value}} selected {{/if}}value="{{value}}">{{label}}</option>
{{/each}}
</select>
</div>
<div class="form-field">
<select class="form-select" name="{{day.name}}" id="{{id}}_day" data-label="day" aria-required="{{required}}" {{#if private_id}}data-field-type="{{private_id}}"{{/if}}>
<select class="form-select"
name="{{day.name}}"
id="{{id}}_day"
data-label="day"
data-input
aria-required="{{required}}"
{{#if private_id}}data-field-type="{{private_id}}"{{/if}}
>
{{#each day.items}}
<option {{#if ../day.value '==' value}} selected {{/if}}value="{{value}}">{{label}}</option>
{{/each}}
</select>
</div>
<div class="form-field">
<select class="form-select" name="{{year.name}}" id="{{id}}_year" data-label="year" aria-required="{{required}}" {{#if private_id}}data-field-type="{{private_id}}"{{/if}}>
<select class="form-select"
name="{{year.name}}"
id="{{id}}_year"
data-label="year"
data-input
aria-required="{{required}}"
{{#if private_id}}data-field-type="{{private_id}}"{{/if}}
>
{{#each year.items}}
<option {{#if ../year.value '==' value}} selected {{/if}}value="{{value}}">{{label}}</option>
{{/each}}
Expand Down
12 changes: 11 additions & 1 deletion templates/components/common/forms/multiline.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,15 @@
<small>{{lang 'common.required' }}</small>
{{/if}}
</label>
<textarea name="{{name}}" id="{{id}}_input" data-label="{{label}}" rows="{{rows}}" aria-required="{{required}}" class="form-input" {{#if private_id}}data-field-type="{{private_id}}"{{/if}}>{{value}}</textarea>
<textarea name="{{name}}"
id="{{id}}_input"
data-label="{{label}}"
rows="{{rows}}"
aria-required="{{required}}"
data-input
class="form-input"
{{#if private_id}}data-field-type="{{private_id}}"{{/if}}
>
{{value}}
</textarea>
</div>
15 changes: 14 additions & 1 deletion templates/components/common/forms/number.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,18 @@
<label class="form-label" for="{{id}}_input">{{label}}
{{#if required}}<small>{{lang 'common.required' }}</small>{{/if}}
</label>
<input type="number" class="form-input" data-label="{{label}}" data-rule="lowerThan" min="{{limitfrom}}" max="{{limitto}}" title="{{lang 'forms.range' limitFrom=limitfrom limitTo=limitto}}" value="{{value}}" id="{{id}}_input" name="{{name}}" aria-required="{{required}}" {{#if private_id}}data-field-type="{{private_id}}"{{/if}}>
<input type="number"
class="form-input"
data-label="{{label}}"
data-input
data-rule="lowerThan"
min="{{limitfrom}}"
max="{{limitto}}"
title="{{lang 'forms.range' limitFrom=limitfrom limitTo=limitto}}"
value="{{value}}"
id="{{id}}_input"
name="{{name}}"
aria-required="{{required}}"
{{#if private_id}}data-field-type="{{private_id}}"{{/if}}
>
</div>
11 changes: 10 additions & 1 deletion templates/components/common/forms/password.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,14 @@
<small>{{lang 'common.required' }}</small>
{{/if}}
</label>
<input type="password" class="form-input" id="{{id}}_input" data-label="{{label}}" name="{{name}}" value="{{value}}" autocomplete="off" aria-required="{{required}}" {{#if private_id}}data-field-type="{{private_id}}"{{/if}}>
<input type="password"
class="form-input"
id="{{id}}_input"
data-label="{{label}}"
name="{{name}}"
value="{{value}}"
autocomplete="off"
aria-required="{{required}}"
{{#if private_id}}data-field-type="{{private_id}}"{{/if}}
>
</div>
12 changes: 5 additions & 7 deletions templates/components/common/forms/radio.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,18 @@
</label>
{{#if radios}}
{{#each radios}}
<input
<input
type="radio"
class="form-radio"
name="{{../name}}"
id="{{../name}}_{{@index}}"
value="{{value}}"
data-label="{{label}}"
data-input
aria-required="{{required}}"
{{#if checked}}
checked
{{/if}}
{{#if private_id}}
data-field-type="{{private_id}}"
{{/if}}>
{{#if checked}}checked{{/if}}
{{#if private_id}}data-field-type="{{private_id}}"{{/if}}
>
<label class="form-label" for="{{../name}}_{{@index}}">{{label}}</label>
{{/each}}
{{/if}}
Expand Down
12 changes: 9 additions & 3 deletions templates/components/common/forms/select.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@
<label class="form-label" for="{{id}}_select">{{label}}
{{#if required}}<small>{{lang 'common.required' }}</small>{{/if}}
</label>
<select class="{{class}} form-select" id="{{id}}_select" data-label="{{label}}" aria-required="{{required}}" name="{{name}}"
{{#if private_id}} data-field-type="{{private_id}}" {{/if}}>
<select class="{{class}} form-select"
id="{{id}}_select"
data-label="{{label}}"
data-input
aria-required="{{required}}"
name="{{name}}"
{{#if private_id}} data-field-type="{{private_id}}" {{/if}}
>
{{#if options}}
<option value="">{{chooseprefix}}</option>
{{#each options}}
<option {{#if selected}} selected {{/if}} value="{{value}}">{{{label}}}</option>
{{/each}}
{{/if}}
</select>
</div>
</div>
19 changes: 17 additions & 2 deletions templates/components/common/forms/selectortext.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,30 @@
<label class="form-label" for="{{id}}_input">{{label}}
{{#if required}}<small>{{lang 'common.required' }}</small>{{/if}}
</label>
<input type="text" id="{{id}}_input" name="{{name}}" value="{{value}}" class="form-input" aria-required="{{required}}" data-label="{{label}}" />
<input type="text"
id="{{id}}_input"
name="{{name}}"
value="{{value}}"
class="form-input"
aria-required="{{required}}"
data-label="{{label}}"
data-input
/>
</noscript>

<label class="form-label" for="{{id}}_select">{{label}}
{{#if required}}
<small>{{lang 'common.required'}}</small>
{{/if}}
</label>
<select name="{{name}}" class="form-select" aria-required="{{required}}" id="{{id}}_select" data-label="{{label}}" {{#if private_id}}data-field-type="{{private_id}}"{{/if}}>
<select name="{{name}}"
class="form-select"
aria-required="{{required}}"
id="{{id}}_select"
data-label="{{label}}"
data-input
{{#if private_id}}data-field-type="{{private_id}}"{{/if}}
>
{{#if options}}
<option value="">{{chooseprefix}}</option>
{{#each options}}
Expand Down
13 changes: 12 additions & 1 deletion templates/components/common/forms/text.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,16 @@
<label class="form-label" for="{{id}}_input">{{label}}
{{#if required}}<small>{{lang 'common.required' }}</small>{{/if}}
</label>
<input type="text" id="{{id}}_input" data-label="{{label}}" name="{{name}}" {{#if value}} value="{{value}}"{{/if}} {{#if placeholder}} placeholder="{{placeholder}}"{{/if}} class="form-input" aria-required="{{required}}" {{#if private_id}}data-field-type="{{private_id}}"{{/if}} {{#if maxlength}}maxlength="{{maxlength}}"{{/if}}>
<input type="text"
name="{{name}}"
id="{{id}}_input"
class="form-input"
data-label="{{label}}"
data-input
aria-required="{{required}}"
{{#if value}} value="{{value}}"{{/if}}
{{#if maxlength}}maxlength="{{maxlength}}"{{/if}}
{{#if placeholder}} placeholder="{{placeholder}}"{{/if}}
{{#if private_id}}data-field-type="{{private_id}}"{{/if}}
>
</div>
2 changes: 1 addition & 1 deletion templates/components/products/modals/writeReview.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ <h5 class="product-title">{{ product.title }}</h5>
</label>
<!-- Stars -->
<!-- TODO: Review Stars need to be componentised, both for display and input -->
<select id="rating-rate" class="form-select" name="revrating">
<select id="rating-rate" class="form-select" name="revrating" data-input>
<option value="">{{lang 'products.reviews.select_rating'}}</option>
{{#for 1 5}}
{{#if ../product.reviews.selected_rating '===' $index}}
Expand Down