Overview
User feedback is a widget at the end of a page. It asks the visitor what they think, in three steps: a question, a follow-up form, and a success message. The Survey structure asks a Yes or No question about the page. The Rating structure asks for a star score for a service. The widget sits in a form, which it validates and sends on Submit.
Pick another component when:
Markup
Variants
Each structure is the whole page section, form included. Submit validates the form, so keep the <form class="nds-form">.
| Group | Option | Markup | On element | Use |
|---|---|---|---|---|
| Structure | Survey (default) | — | — | A Yes or No question about the page, with reasons for each answer. Content pages |
| Structure | Rating | canon #uf-rating |
— | A star score for a service, with a comment. Service pages |
| Statistic | No statistic | remove | .nds-user-feedback-statistic |
Leave it out when you have no real numbers to show |
| Gender | No gender question | remove | .nds-gender |
Leave it out when your service does not report answers by gender |
| Agreement | No agreement line | remove | .nds-user-feedback-agreement |
Leave it out when the site has no participation statement or rules page. Keep it with links to the real pages |
| Memory | Ask every visit (hint: No cookie saves the answer) | [data-no-persist] |
.nds-user-feedback |
No cookie: the widget asks again on every visit |
| Field states | Label, info, feedback, required | — | — | Shared by every form field. See Forms |
Behavior
Survey
Yes or No opens the follow-up form with the reasons for that answer: .nds-why-yes or .nds-why-no. The other fields, such as the comment, show for both answers. Close clears every field and goes back to the question.
Rating
The widget shows the average score and the review count. The button opens a star rating with a comment. The script writes the chosen score into the hidden data-rating-value input on each pick, so the form sends it. It also writes the score into the recap, which replaces the question.
Submit
After the checks pass, Submit sends the form data to the form’s action with NDS.request. A spinner shows until the reply. A reply from 200 to 299 shows the success message. Any other reply, or no reply, shows the error message and keeps the form open, so the visitor can send it again. With no action, the success message shows at once. The built-in send posts multipart/form-data with no custom headers, and ignores the reply body. For JSON or a header, send the data yourself.
Your Own Request
To send the data another way, listen for nds:user-feedback:submit and call preventDefault(). Send e.detail.data, then call NDS.UserFeedback.setStatus() with 'success' or 'error'. The messages work as they do for an action, but the spinner is yours to show. The example is in the API section.
e.detail.data holds each checked box as its own entry with the same name. For a JSON body, read a group with data.getAll('why-yes'): Object.fromEntries() keeps only the last box.
Built-in Features
-
Auto-initialization
The loader starts every
.nds-user-feedbackon the page. No init call is needed. -
Submission Memory
After a success, a cookie for the page path is saved for 365 days. On the next visit, the widget shows the success message instead of the question. The cookie is necessary, so it needs no consent.
-
Bilingual Feedback Messages
The success and error messages follow the page language, Arabic or English.
-
Form Validation
Submit checks every field rule, such as
data-requiredanddata-min-checked, before it sends. Focus moves to the first field that fails. -
Scroll After Submit
When the message shows and the widget is hidden under the sticky navigation, the page scrolls the widget back into view.
-
Mobile Layout
On phones, each row stacks, and Close moves to the top of the widget.
Best Practices
- Put the widget after the main content, as the last section of the page.
- Use Survey on content pages, where the question is about the page. Use Rating on service pages, where the visitor judges the service.
- Set
actionon the form to your endpoint, or send the data yourself fromnds:user-feedback:submit. Without either, nothing is sent. - Leave the widget off task pages, such as a checkout, a multi-step form or a confirmation screen. The visitor’s attention belongs on the task.
- Write reasons that fit the page, four to six in each list.
- Remove the statistic when you have no real numbers to show. In Rating, write the real average in the question and in
data-rating. - The gender question and the agreement line are sample content. Keep each one only when it is true for your service, and link the agreement line to your real pages.
- Keep the
.nds-noteafter the legend, not inside it. The group’s name then stays short, and a screen reader still reads the note througharia-describedby. - Do not make the widget the only way to report a problem. Link to a support form too.
- On a page built with the NDS layouts, the layout adds the Survey. Set
feedback_type: ratingin the front matter for Rating, orhideFeedback: truefor none.rating: trueis a different key: the hero’s rating menu.
API
Classes
| Class | Element | Effect |
|---|---|---|
nds-user-feedback-section |
the page section | Primary top border and the default background |
nds-why-yes, nds-why-no |
a fieldset in the details | Shows only for the matching answer |
nds-user-feedback-statistic |
a span | Hides while the form is open |
nds-user-feedback-rating |
.nds-user-feedback |
The Rating structure. It shows the prompt while the form is open, and the recap after a success |
nds-user-feedback-score |
the stars and the review count | Keeps them on one line. Hides while the form is open |
Data Attributes
| Attribute | Element | Effect |
|---|---|---|
data-answer |
an answer button | Yes or No, with a capital letter, opens the matching reasons. Any other value, such as rate, opens the form with no reasons |
data-answer |
.nds-user-feedback |
Set by the script: yes or no. Close removes it |
data-state |
.nds-user-feedback |
Set by the script: details while the form is open, status after a success. status hides the question and the answer buttons. There is no value at the question step |
data-success-message |
.nds-user-feedback |
Replaces the success message, as plain text, in every language. The default is “Your feedback is submitted!” or «تم استلام ملاحظتك!» |
data-error-message |
.nds-user-feedback |
Replaces the error message, as plain text, in every language. The default is “An error occurred, please try again” or «حدث خطأ، يرجى المحاولة مرة أخرى» |
data-no-persist |
.nds-user-feedback |
No cookie: the widget never shows a saved success and never saves one |
data-rating-value |
a hidden input | Receives the chosen score on each pick. Rating shares it |
data-rating-score |
an element in the recap | Shows the chosen score, as (4.0) |
action, method |
the form | Where Submit sends the form data. The default method is POST |
The field rules (data-required, data-min-checked) and data-feedback-target work as on every field. See Forms.
CSS Custom Properties
| Property | Default | Controls |
|---|---|---|
--userfeedback-scroll-offset |
120px |
Space between the sticky navigation and the widget after the scroll. Set it on .nds-user-feedback |
Tokens
It reads these shared tokens. A change to one also changes other components: see Tokens.
Source: the var() reads in _sass/components/_user-feedback.scss.
| Token | Preview | Value |
|---|---|---|
--background-defaultRead by background | var(--colors-base-white)Dark mode var(--colors-neutral-800) | |
--border-primaryRead by border-top | var(--colors-primary-600) | |
--link-primaryRead by --link-color | var(--text-primary)Dark mode var(--colors-primary-400) | |
--link-primary-hoveredRead by --link-hover | var(--colors-primary-700)Dark mode var(--colors-primary-300) | |
--link-primary-pressedRead by --link-pressed | var(--colors-primary-800)Dark mode var(--colors-primary-200) |
JavaScript
The NDS.UserFeedback script loads after the page shows. Until it loads, each call loads it and returns a promise of the result, so await a call whose result you use.
| Method | Effect |
|---|---|
NDS.UserFeedback.init() |
Starts every .nds-user-feedback that is not started |
NDS.UserFeedback.create(el) |
Starts one widget |
NDS.UserFeedback.destroy(el) |
Removes the widget’s listeners, so create() can start it again |
NDS.UserFeedback.setStatus(el, status) |
Ends a send that your listener took over: 'success' (default) or 'error' |
| Event | Fired on | Detail |
|---|---|---|
nds:user-feedback:submit |
.nds-user-feedback (bubbles, cancelable) |
{ form, data }. data is the form’s FormData. It fires after the form passes its checks |
The full API is in the banner of _js/nds-user-feedback.js.