diff --git a/src/components/MDXComponents/MDXTable.tsx b/src/components/MDXComponents/MDXTable.tsx index 31f07b8142f..0d23bcec839 100644 --- a/src/components/MDXComponents/MDXTable.tsx +++ b/src/components/MDXComponents/MDXTable.tsx @@ -1,18 +1,40 @@ import { ScrollView } from '@aws-amplify/ui-react'; -import { HTMLAttributes, ReactNode } from 'react'; +import { HTMLAttributes, ReactNode, useEffect, useRef, useState } from 'react'; interface MDXTableProps extends HTMLAttributes { children: ReactNode; } export const MDXTable: React.FC = ({ children, ...props }) => { + const ref = useRef(null); + const [caption, setCaption] = useState(''); + + useEffect(() => { + const getHeading = (el) => { + if (el?.previousElementSibling?.tagName.startsWith('H')) { + setCaption(el.previousElementSibling.textContent); + } else { + getHeading(el?.previousElementSibling); + } + }; + getHeading(ref.current); + }, []); + + const tableId = caption.includes(' ') ? caption.split(' ').join('') : caption; + return ( - {children}
+ + + {children} +
Table: {caption}
); }; diff --git a/src/components/MDXComponents/__tests__/MDXTable.test.tsx b/src/components/MDXComponents/__tests__/MDXTable.test.tsx index 6290b28bbe6..a4110eb01ac 100644 --- a/src/components/MDXComponents/__tests__/MDXTable.test.tsx +++ b/src/components/MDXComponents/__tests__/MDXTable.test.tsx @@ -4,54 +4,57 @@ import { MDXTable } from '../MDXTable'; describe('MDXTable', () => { it('should render table', () => { render( - - - - - Amplify Authenticator - Amplify Libraries - - - - - - Description - - - Open source drop-in UI component for authentication - - - Low-level building blocks for implementing authentication - - - - - Benefits - - - Automatically integrates with your existing Amplify configuration - and allows you to easily add the entire authentication flow to - your application. You can then customize themes to adjust colors - and styling as needed. - - - Gives you full control over the UI and logic implementation. - - - - - Constraints - - - Dependent on Amplify CLI for provisioning resources. - - - Requires the building of screens and frontend logic to enable the - sign-in and registration experiences. - - - - +
+

Heading

+ + + + + Amplify Authenticator + Amplify Libraries + + + + + + Description + + + Open source drop-in UI component for authentication + + + Low-level building blocks for implementing authentication + + + + + Benefits + + + Automatically integrates with your existing Amplify + configuration and allows you to easily add the entire + authentication flow to your application. You can then customize + themes to adjust colors and styling as needed. + + + Gives you full control over the UI and logic implementation. + + + + + Constraints + + + Dependent on Amplify CLI for provisioning resources. + + + Requires the building of screens and frontend logic to enable + the sign-in and registration experiences. + + + + +
); const tableHeading = screen.getByText('Amplify Authenticator'); diff --git a/src/styles/table.scss b/src/styles/table.scss index c881ce78f1b..2606b1112cd 100644 --- a/src/styles/table.scss +++ b/src/styles/table.scss @@ -19,6 +19,10 @@ table:not([class]) { background-color: var(--amplify-colors-neutral-10); } } + caption { + visibility: hidden; + line-height: 0; + } } .scrollview {