Skip to content

Commit

Permalink
feat: support exposing Feedback as a landmark if needed
Browse files Browse the repository at this point in the history
  • Loading branch information
ivarni committed Sep 27, 2024
1 parent b511dfc commit 5c1710a
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 7 deletions.
11 changes: 10 additions & 1 deletion packages/feedback-react/src/Feedback.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,24 @@ type Props = {
* - `message`: Eventuell utfyllende melding fra bruker. Blir kun sendt inn ved aktiv innsending
*/
onSubmit: (value: FeedbackType) => void;

followup?: FollowupProps;
contactQuestion?: ContactQuestionProps;
/**
* Hvis du ønsker at Feedback formen skal eksponeres som et landmark kan du sende inn
* hva du ønsker at en skjermleser skal kalle den her. Bare eksponer Feedback som et
* landmark på sider der den er en viktig del av innholdet, feks en kvitteringsside
* eller et annet sted det å kunne gi tilbakemelding vil føles naturlig eller forventet
* for brukeren.
*/
landmarkLabel?: string;
} & Pick<BaseTextAreaProps, "counter">;

export const Feedback = ({
className,
followup,
contactQuestion,
counter,
landmarkLabel,
...mainQuestionProps
}: Props): ReactElement => {
const [feedbackSubmitted, setFeedbackSubmitted] = useState(false);
Expand All @@ -67,6 +75,7 @@ export const Feedback = ({
followupSubmitted,
contactSubmitted,
counter,
landmarkLabel,
setFeedbackSubmitted,
setFollowupStarted,
setFollowupSubmitted,
Expand Down
1 change: 1 addition & 0 deletions packages/feedback-react/src/feedbackContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ type FeedbackContext = {
followupStarted: boolean;
followupSubmitted: boolean;
contactSubmitted: boolean;
landmarkLabel?: string;
setFeedbackSubmitted: (state: boolean) => void;
setFollowupStarted: (state: boolean) => void;
setFollowupSubmitted: (state: boolean) => void;
Expand Down
5 changes: 3 additions & 2 deletions packages/feedback-react/src/followup/Followup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ export const Followup: FC<Props> = ({ questions, successMessage = defaultSuccess
const focusRef = useRef<HTMLParagraphElement>(null);
const followupState = useFollowup(questions, onSubmit);
const { handleAbort, handleNext, step, submitted } = followupState;
const { followupStarted, setFollowupStarted, setFollowupSubmitted, contactSubmitted } = useFeedbackContext();
const { followupStarted, setFollowupStarted, setFollowupSubmitted, contactSubmitted, landmarkLabel } =
useFeedbackContext();

useEffect(() => {
if (step.number === 0) {
Expand Down Expand Up @@ -67,7 +68,7 @@ export const Followup: FC<Props> = ({ questions, successMessage = defaultSuccess
</div>
)}
{!submitted && followupStarted && (
<form onSubmit={handleNext} className="jkl-feedback__fade-in">
<form onSubmit={handleNext} className="jkl-feedback__fade-in" aria-label={landmarkLabel}>
<p className="jkl-feedback__step-counter" ref={focusRef}>
Steg {step.number + 1} av {questions.length}
</p>
Expand Down
4 changes: 2 additions & 2 deletions packages/feedback-react/src/main-question/MainQuestion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const MainQuestion: FC<Props> = ({
}) => {
const mainQuestionState = useMainQuestion(onSubmit);

const { setFeedbackSubmitted, contactSubmitted } = useFeedbackContext();
const { setFeedbackSubmitted, contactSubmitted, landmarkLabel } = useFeedbackContext();
const { handleSubmit, currentValue, setCurrentValue, submitted } = mainQuestionState;
const [submitWrapperRef] = useAnimatedHeight<HTMLDivElement>(currentValue !== undefined);

Expand All @@ -54,7 +54,7 @@ export const MainQuestion: FC<Props> = ({
<>
{!submitted && (
<MainQuestionContextProvider state={mainQuestionState}>
<form onSubmit={handleSubmit}>
<form onSubmit={handleSubmit} aria-label={landmarkLabel}>
<MainQuestionComp label={label} options={options} helpLabel={helpLabel} />
<div
ref={submitWrapperRef}
Expand Down
4 changes: 2 additions & 2 deletions packages/feedback-react/src/questions/ContactQuestion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export const ContactQuestion: FC<Props> = ({
const [shouldValidate, setShouldValidate] = useState(false);

const [noThanks, setNoThanks] = useState(false);
const { contactSubmitted, setContactSubmitted } = useFeedbackContext();
const { contactSubmitted, setContactSubmitted, landmarkLabel } = useFeedbackContext();

const ChildrenWrapper = typeof children === "string" ? "p" : "div";

Expand Down Expand Up @@ -122,7 +122,7 @@ export const ContactQuestion: FC<Props> = ({
}

return (
<form className="jkl-spacing-xl--top" onSubmit={handleSubmit}>
<form className="jkl-spacing-xl--top" onSubmit={handleSubmit} aria-label={landmarkLabel}>
<p className="jkl-heading-4 jkl-spacing-xs--bottom">{label}</p>
{children && <ChildrenWrapper className="jkl-body">{children}</ChildrenWrapper>}

Expand Down

0 comments on commit 5c1710a

Please sign in to comment.