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(feedback/v7): Make "required" text for input elements configurable #11287

Merged
merged 3 commits into from
Mar 27, 2024
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 packages/feedback/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export const MESSAGE_PLACEHOLDER = "What's the bug? What did you expect?";
export const MESSAGE_LABEL = 'Description';
export const NAME_PLACEHOLDER = 'Your Name';
export const NAME_LABEL = 'Name';
export const IS_REQUIRED_LABEL = '(required)';
export const SUCCESS_MESSAGE_TEXT = 'Thank you for your report!';

export const FEEDBACK_WIDGET_SOURCE = 'widget';
Expand Down
3 changes: 3 additions & 0 deletions packages/feedback/src/integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
EMAIL_LABEL,
EMAIL_PLACEHOLDER,
FORM_TITLE,
IS_REQUIRED_LABEL,
MESSAGE_LABEL,
MESSAGE_PLACEHOLDER,
NAME_LABEL,
Expand Down Expand Up @@ -105,6 +106,7 @@ export class Feedback implements Integration {
messageLabel = MESSAGE_LABEL,
namePlaceholder = NAME_PLACEHOLDER,
nameLabel = NAME_LABEL,
isRequiredLabel = IS_REQUIRED_LABEL,
successMessageText = SUCCESS_MESSAGE_TEXT,

onFormClose,
Expand Down Expand Up @@ -152,6 +154,7 @@ export class Feedback implements Integration {
messagePlaceholder,
nameLabel,
namePlaceholder,
isRequiredLabel,
successMessageText,

onFormClose,
Expand Down
5 changes: 5 additions & 0 deletions packages/feedback/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ export interface FeedbackTextConfiguration {
* Message after feedback was sent successfully
*/
successMessageText: string;

/**
* Label shown when an input field is required
*/
isRequiredLabel: string;
}

/**
Expand Down
9 changes: 6 additions & 3 deletions packages/feedback/src/widget/Form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export function Form({
emailPlaceholder,
messageLabel,
messagePlaceholder,
isRequiredLabel,
cancelButtonLabel,
submitButtonLabel,

Expand Down Expand Up @@ -176,7 +177,8 @@ export function Form({
'span',
{ className: 'form__label__text' },
nameLabel,
isNameRequired && createElement('span', { className: 'form__label__text--required' }, ' (required)'),
isNameRequired &&
createElement('span', { className: 'form__label__text--required' }, ` ${isRequiredLabel}`),
),
nameEl,
],
Expand All @@ -195,7 +197,8 @@ export function Form({
'span',
{ className: 'form__label__text' },
emailLabel,
isEmailRequired && createElement('span', { className: 'form__label__text--required' }, ' (required)'),
isEmailRequired &&
createElement('span', { className: 'form__label__text--required' }, ` ${isRequiredLabel}`),
),
emailEl,
],
Expand All @@ -213,7 +216,7 @@ export function Form({
'span',
{ className: 'form__label__text' },
messageLabel,
createElement('span', { className: 'form__label__text--required' }, ' (required)'),
createElement('span', { className: 'form__label__text--required' }, ` ${isRequiredLabel}`),
),
messageEl,
],
Expand Down
1 change: 1 addition & 0 deletions packages/feedback/src/widget/createWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ export function createWidget({
messagePlaceholder: options.messagePlaceholder,
nameLabel: options.nameLabel,
namePlaceholder: options.namePlaceholder,
isRequiredLabel: options.isRequiredLabel,
defaultName: (userKey && user && user[userKey.name]) || '',
defaultEmail: (userKey && user && user[userKey.email]) || '',
onClosed: () => {
Expand Down
2 changes: 2 additions & 0 deletions packages/feedback/test/widget/Dialog.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ function renderDialog({
messagePlaceholder = 'What is the issue?',
cancelButtonLabel = 'Cancel!',
submitButtonLabel = 'Submit!',
isRequiredLabel = '(needed!)',
...rest
}: Partial<DialogProps> = {}) {
return Dialog({
Expand All @@ -44,6 +45,7 @@ function renderDialog({
messagePlaceholder,
cancelButtonLabel,
submitButtonLabel,
isRequiredLabel,
...rest,
}) as NonNullableFields<ReturnType<typeof Dialog>>;
}
Expand Down
8 changes: 5 additions & 3 deletions packages/feedback/test/widget/Form.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ function renderForm({
messagePlaceholder = 'What is the issue?',
cancelButtonLabel = 'Cancel!',
submitButtonLabel = 'Submit!',
isRequiredLabel = '(needed!)',
...rest
}: Partial<FormComponentProps> = {}) {
return Form({
Expand All @@ -37,6 +38,7 @@ function renderForm({
messagePlaceholder,
cancelButtonLabel,
submitButtonLabel,
isRequiredLabel,
...rest,
}) as NonNullableFields<ReturnType<typeof Form>>;
}
Expand Down Expand Up @@ -89,9 +91,9 @@ describe('Form', () => {
const nameLabel = formComponent.el.querySelector('label[htmlFor="name"]') as HTMLLabelElement;
const emailLabel = formComponent.el.querySelector('label[htmlFor="email"]') as HTMLLabelElement;
const messageLabel = formComponent.el.querySelector('label[htmlFor="message"]') as HTMLLabelElement;
expect(nameLabel.textContent).toBe('Name! (required)');
expect(emailLabel.textContent).toBe('Email! (required)');
expect(messageLabel.textContent).toBe('Description! (required)');
expect(nameLabel.textContent).toBe('Name! (needed!)');
expect(emailLabel.textContent).toBe('Email! (needed!)');
expect(messageLabel.textContent).toBe('Description! (needed!)');

const nameInput = formComponent.el.querySelector('[name="name"]') as HTMLInputElement;
const emailInput = formComponent.el.querySelector('[name="email"]') as HTMLInputElement;
Expand Down
2 changes: 2 additions & 0 deletions packages/feedback/test/widget/createWidget.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
EMAIL_LABEL,
EMAIL_PLACEHOLDER,
FORM_TITLE,
IS_REQUIRED_LABEL,
MESSAGE_LABEL,
MESSAGE_PLACEHOLDER,
NAME_LABEL,
Expand Down Expand Up @@ -47,6 +48,7 @@ const DEFAULT_OPTIONS = {
messageLabel: MESSAGE_LABEL,
namePlaceholder: NAME_PLACEHOLDER,
nameLabel: NAME_LABEL,
isRequiredLabel: IS_REQUIRED_LABEL,
successMessageText: SUCCESS_MESSAGE_TEXT,

onFormClose: jest.fn(),
Expand Down
Loading