-
Notifications
You must be signed in to change notification settings - Fork 14
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
fix(PPDSC-2203): handling non text children in Paragraph #221
Conversation
You can preview these changes on: |
|
||
export const Paragraph: React.FC<ParagraphProps> = ({ | ||
children, | ||
children: ch, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would keep "children", why are we using an alias such as ch
? I think makes it bit less easy to understand what is it
</ParagraphDropCap> | ||
{firstWord.slice(1)}{' '} | ||
</span> | ||
<ScreenReaderOnly>{firstWord}</ScreenReaderOnly> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please go through the "manual tests" relevant to this ticket? The different browsers and Screen reader testing 🤔 ?
I can see how the screen reader is not behaving anymore as it should. How was before did allow a smooth reading of the paragraph, not you need extra steps! I can show you. I wonder if the return of the Paragraph component could be simplified into something like
return (
<ParagraphText>
{useDropCap && (
<>
<span aria-hidden="true">
<ParagraphDropCap overrides={overrides}>
{firstWord[0]}
</ParagraphDropCap>
removeFirstLetter(children)
</span>
<ScreenReaderOnly>{children}</ScreenReaderOnly>
</>
)}
</ParagraphText>
);
In this way you won't need any extra ternary statement and the SR will read it properly. Happy to jump on a call
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have changed it a bit, let me know what you think
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we have a storybook scenario? The rest looks good
): string => { | ||
const [firstChild] = children; | ||
if (typeof firstChild === 'string') { | ||
return firstChild.split('')[0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tiny but you can use .charAt
for getting the first letter of a string like so
return firstChild.charAt(0);
): (React.ReactChild | React.ReactFragment | React.ReactPortal)[] => { | ||
const [firstChild, ...rest] = children; | ||
if (typeof firstChild === 'string') { | ||
return [firstChild.split('').slice(1).join(''), ...rest]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly I think we can use .substring(1)
instead of firstChild.split('').slice(1).join('')
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good ones, thanks
* fix(PPDSC-2203): handle multilpe children in paragraph * fix(PPDSC-2203): fix css issue * fix(PPDSC-2203): add comment * fix(PPDSC-2203): address some of comments * fix(PPDSC-2203): fix a11y issue in the paragraph * fix(PPDSC-2203): add a story * fix(PPDSC-2203): update unit tests * fix(PPDSC-2203): fix coverage * fix(PPDSC-2203): change from arrat to string methods
PPDSC-2203
What
text <b>other</b>
since for React treads that as multiple children2.1. - Updated code so that handles multiple children, and adjusted the ScreenOnly content, to wrap only first word instead of the whole paragraph text
2.2. - When the first child is not a text it will not show the drop-cap.
2.3. - Added support for React.Fragment
I have done:
I have tested manually:
Before:
After:
Who should review this PR:
How to test: