From 6c36c1ff3162a268ddd8581d800adfabe1165019 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20H=C3=B8egh?= Date: Tue, 15 Nov 2022 13:20:10 +0100 Subject: [PATCH] chore(Table): docs and housekeeping (#1722) I see that we need some refactoring, while working on another larger PR. --- .../src/docs/uilib/components/table/info.md | 7 ++++ .../src/components/table/Table.tsx | 10 ++++- .../src/components/table/TableTd.tsx | 13 ++---- .../src/components/table/TableTr.tsx | 40 ++++++------------- 4 files changed, 31 insertions(+), 39 deletions(-) diff --git a/packages/dnb-design-system-portal/src/docs/uilib/components/table/info.md b/packages/dnb-design-system-portal/src/docs/uilib/components/table/info.md index 184521c2795..ccf78e874ca 100644 --- a/packages/dnb-design-system-portal/src/docs/uilib/components/table/info.md +++ b/packages/dnb-design-system-portal/src/docs/uilib/components/table/info.md @@ -12,6 +12,13 @@ Tables do both serve as a way of navigation for screen readers and other asserti Use the documentation from [MDN – The Table element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/table) for more information on making semantic correct tables, including `scope`, `align`, `colSpan` and `rowSpan`. +Here is a list of things you may follow along in order to ensure your coded tables still are accessible: + +- Keep a semantic correct structure. +- Let tables align the column width, when possible. +- Do not use CSS `display` property on any table element. +- Do not overwrite styles in general, but rather get in touch with DNB UX. + ## Table header components - `` to be used for additional sorting functionality. diff --git a/packages/dnb-eufemia/src/components/table/Table.tsx b/packages/dnb-eufemia/src/components/table/Table.tsx index 901fea1bc54..07770bd2026 100644 --- a/packages/dnb-eufemia/src/components/table/Table.tsx +++ b/packages/dnb-eufemia/src/components/table/Table.tsx @@ -111,7 +111,15 @@ const Table = ( return ( -) => { - const { - className, - children, - - ...props - } = componentProps +) { + const { className, children, ...props } = componentProps return ( + {children} ) } -export default Tr - -function useHandleTrLogic({ tableContext, variant }) { - const trRef = React.useRef(null) +function useHandleTrVariant({ variant }) { + const tableContext = React.useContext(TableContext) /** * Handle odd/even @@ -112,11 +100,7 @@ function useHandleTrLogic({ tableContext, variant }) { currentVariant = count % 2 ? 'odd' : 'even' } - const trParams = {} - return { - trRef, currentVariant, - trParams, } }
) } - -export default Td diff --git a/packages/dnb-eufemia/src/components/table/TableTr.tsx b/packages/dnb-eufemia/src/components/table/TableTr.tsx index aa8be62606a..327ff514ab0 100644 --- a/packages/dnb-eufemia/src/components/table/TableTr.tsx +++ b/packages/dnb-eufemia/src/components/table/TableTr.tsx @@ -17,46 +17,34 @@ export type TableTrProps = { | Array> } -const Tr = ( +export default function Tr( componentProps: TableTrProps & React.TableHTMLAttributes -) => { +) { const { variant, - className, children, - + className: _className, ...props } = componentProps - const tableContext = React.useContext(TableContext) + const { currentVariant } = useHandleTrVariant({ variant }) - const { currentVariant, trRef, trParams } = useHandleTrLogic({ - tableContext, - variant, - }) + const className = classnames( + 'dnb-table__tr', + currentVariant && `dnb-table__tr--${currentVariant}`, + _className + ) return ( -