Implement `Survey*` UI components for initial rating survey
Feature Description
While user surveys will be capable of displaying multiple questions of various types, the initial implementation will be limited to a single rating-type question only with two potential completions. This issue is about building the necessary UI components for this initial survey – none of which should be specific to the initial survey as far as the contents are concerned; this should all come via props.
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
- A new
SurveyQuestionRatingcomponent should be created inassets/js/components/surveys/- It should require the following props:
question[string] – the question textchoices[array] available 5 answer objects with properties:answer_ordinal[int] andtext[string]answerQuestion[function] should be called with the answer object corresponding to the selected choicedismissSurvey[function] should be called when the close button (X) is clicked
- The text for labelling the low/high ends of the rating spectrum should come from the 1st and 5th choices respectively (passed via props)
- Additionally, each individual choice should have its text value provided (visually hidden) on each choice element for accessibility
- It should require the following props:
- A new
SurveyCompletioncomponent should be created inassets/js/components/surveys/- It should require the following props:
title[string] – primary heading on the survey cardchildren[*] secondary textctaText[string] – text for follow up CTA buttonctaURL[string] – URL for follow up CTA buttonctaOnClick[function] – onClick handler for follow up CTA buttondismissSurvey[function] – should be called when the close button (X) is clicked
- It should require the following props:
- See the design for how this should look
- Common components may be extracted as necessary
- Storybook stories should be added for these two components
Implementation Brief
- Create new file
assets/js/components/surveys/SurveyQuestionRatingwhich exports theSurveyQuestionRatingfunctional component with the props defined in the AC.- Associate each
answer_ordinalto the icon as in the designs in Figma, meaninganswer_ordinal1 will be the unhappy icon andanswer_ordinal5 will be the delighted icon. It's fine to hardcode the icons for now.
- Associate each
- Create new file
assets/js/components/surveys/SurveyCompletionwhich exports theSurveyCompletionfunctional component with the props defined in the AC. - Create new file
assets/js/components/surveys/SurveyHeaderwhich exports theSurveyHeaderfunctional component with the following props:title: [string] – text shown next to the Google logo.dismissSurvey: [function] should be called when the close button (X) is clicked.
SurveyQuestionRatingandSurveyCompletionshould both use theSurveyHeadercomponent to render the top section of the components, i.e where we have the Google logo, text and close button.- Components should be styled as per the designs in Figma, without the fixed position. This will be taken care of in #3375.
- Use the
Grid,RowandCellcomponents for the grid layout.- For rendering the icons, use a
Rowwith 5Cellswhich do no wrap across breakpoints. Each cell will also contain the "text" associated to the icon. For e.g "Unhappy" for 1 and "Delighted" for 5. The value can be obtained via thetextproperty of each choice and theButtoncomponent should be used for rendering the icons. - The texts for Icon 1 and Icon 5 only should be visible at all times.
- For accessibility, each icon should have the text visually hidden via the
aria-labelprop of theButtoncomponent. - As per the designs for desktop, the max width of the component is
400pxand we should be able to reduce the width to320pxon small screens by reducing the padding between grid cells and the icon dimensions if necessary. - Upon hover, each icon should have a darker grey rounded background, similar to what is done for the "Help" icon here: https://google.github.io/site-kit-wp/storybook/develop/?path=/story/global--plugin-header-with-help-menu
- For rendering the icons, use a
- Use the
- SVGs (for the emojis) should be added in the
assets/svgfolder and prefixed withsurvey-. For e.gsurvey-unhappy.svg. - Instead of using the SVG from the designs for the close icon, we can use the
closeSmallicon from@wordpress/icons. https://wordpress.github.io/gutenberg/?path=/story/icons-icon--library - All styles for the above components should go in
assets/sass/components/survey/_googlesitekit-survey.scss. - Any class names used in the component should follow the BEM methodology, with the
googlesitekit-surveyprefix. - Create
SurveyQuestionRating.stories.jsandSurveyCompletion.stories.jswhich will contain the stories for both components.
Test Coverage
- No tests to be added.
Visual Regression Changes
- N/A
QA Brief
Check if the components from the following URLs: * https://google.github.io/site-kit-wp/storybook/pull/3436/?path=/story/components-surveys--survey-question-rating-story * https://google.github.io/site-kit-wp/storybook/pull/3436/?path=/story/components-surveys--survey-completion-story match the designs in Figma.
Changelog entry
- Add React components for rendering user survey UI.
ACs lgtm!
@aaemnnosttv I've suggested we add another property, Icon for the answers object which is not present in the AC. Let me know what you think.
@aaemnnosttv I've suggested we add another property,
Iconfor the answers object which is not present in the AC. Let me know what you think.
@asvinb we can't really do that since choices comes from the API. I think for the rating we can always assume it will be 5 choices but we should use the provided objects and associate them with their respective icons within the component. We also don't need the icons to be flexible right now and I'm not sure that we ever will.
- Components should be styled as per the designs in Figma. * This includes using
fixedpositioning for the surveySurveyQuestionRatingcomponent with a36pxmargin bottom and right.
These components shouldn't be concerned with positioning on the screen since that's only really relevant to the CurrentSurvey. Think of these components more like a base tooltip component. We should be able to write stories for these with the component(s) in place (just like any other) rather than it always rendering in a fixed position.
- Use the
Grid,RowandCellcomponents for the grid layout.
Would you please elaborate a little more on this? What kind of grid do we need for each? How many rows/cols and would it use the same in all viewports?
Ready for another pass @aaemnnosttv
Looks good @asvinb ! The only thing I'm not 💯 sure about is the "Unhappy" and "Delighted" text. I believe this should come from the 1st and 5th answer objects (from their text property) rather than hard-coding a translatable string (as we would normally). This part isn't defined either way in the IB but probably a detail which is missing in the AC too.
@felixarntz – can you clarify if the high/low range labels should be taken from the first and last answer objects or handled the same as normal i18n strings in the plugin?
@asvinb @aaemnnosttv Indeed the labels should come from the API response. As a matter of fact, each of the five options has a human-readable label, and all of these should be considered:
- The ones for the 1 and 5 rating should show on the left and right below the rating icons.
- All from 1 to 5 should show on hover above the faces, or at a minimum be the text used for assistive technologies to which the icons wouldn't mean anything.
Sounds good. IB updated @felixarntz , although I'am not clear for the hover state of each face. I don't see any designs for it. Any idea?
@asvinb Good catch, I thought that had been captured in the Figma file somewhere, but it doesn't look like it.
The hover effect should surface a tooltip with the text as some sort of tooltip, with similar appearance how it is e.g. in Google Drive:

This would be great to do via a generally reusable component, e.g. TooltipIcon or so? For the first iteration though it would be also okay to only use the text as screen reader text and not do any hover effect, since adding that might increase the scope. @aaemnnosttv What do you think? Maybe add a follow-up issue to implement the hover tooltip via a reusable component? Such a component we should eventually then use for e.g. the icons in the Site Kit header bar as well.
This would be great to do via a generally reusable component, e.g.
TooltipIconor so? For the first iteration though it would be also okay to only use the text as screen reader text and not do any hover effect, since adding that might increase the scope. @aaemnnosttv What do you think? Maybe add a follow-up issue to implement the hover tooltip via a reusable component? Such a component we should eventually then use for e.g. the icons in the Site Kit header bar as well.
@felixarntz I think it could be okay to include the component here if it didn't require substantial additional effort. Maybe for now it could be local to surveys/ and we can extract it to something more generic, add stories etc in a follow-up issue. I agree we should keep the scope the same here though so I don't think the ACs need to change that much, but I'll amend them to clarify the source of the text and accessibility details 👍
@asvinb I've updated the ACs to reflect the clarifications from @felixarntz.
Note that the full hover state+tooltip is not required, but is more of a nice to have for now. If it's not going to complicate things we can include it, but otherwise best to leave for a future enhancement. For now, I think we can follow what we already have in the plugin header (e.g. help menu icon) which I believe is just background color and border radius; the color is inherited.
Assigning back to you for any finishing touches, but otherwise I think we're good to go here.
@aaemnnosttv IB updated. Can you review? One notable thing I added is using the Button component to display the icons and then use the aria-label prop to pass the text property of each choice.
IB ✅
Increasing estimate from 11 to 15 to account for additional QA time required for UI changes.
Just noticed @aaemnnosttv was the original reviewer here; in the interest of working on #3380 I'm going to assign this one to him again for now. 😅
QA ⚠️
Need to verify a couple of points below. Apart from those, it all seems good. @aaemnnosttv can you provide any guidance here?
SurveyQuestionRating
- A new component has been created in the specified location
- The new component requires the correct props
- The text for the low and high ends come from the 1st and 5th choice props, as specified.
- ⚠️ Text on the choices is visually hidden, but this is done with
display: none;, which I believe hides the text from screen readers. - ⚠️ The component looks exactly like the designs as far as I can make out, although at storybook's 'small mobile' setting, it overflows:

SurveyCompletion
- A new component has been created in the specified location
- The new component requires the correct props
- The component looks exactly like the designs
⚠️ Text on the choices is visually hidden, but this is done with
display: none;, which I believe hides the text from screen readers.
@johnPhillips that may be but this text is not intended for screen readers; each button wrapping the choices gets an appropriate aria-label attribute for this purpose.
⚠️ The component looks exactly like the designs as far as I can make out, although at storybook's 'small mobile' setting, it overflows
Taking a closer look, the main problem there is the added 50px of padding on either side which isn't representative of the components. That's not to say either whether or not we would want to show these in mobile at all. Since this issue is just about the UI component though, the overflow only starts to happen at a width below 260px which is likely smaller than most phones so it's not something we need to worry about now I think.

Thanks @aaemnnosttv!
QA ✅