diff --git a/.changeset/purple-lies-teach.md b/.changeset/purple-lies-teach.md new file mode 100644 index 000000000..4e1c5cca9 --- /dev/null +++ b/.changeset/purple-lies-teach.md @@ -0,0 +1,5 @@ +--- +'gitbook': patch +--- + +Show definition title when visible in cards diff --git a/packages/gitbook/src/components/DocumentView/Blocks.tsx b/packages/gitbook/src/components/DocumentView/Blocks.tsx index 32260fdae..c6c55bc2b 100644 --- a/packages/gitbook/src/components/DocumentView/Blocks.tsx +++ b/packages/gitbook/src/components/DocumentView/Blocks.tsx @@ -16,7 +16,7 @@ export function Blocks; }, ) { - const { nodes, tag: Tag = 'div', style, blockStyle, ...contextProps } = props; + const { nodes, tag: Tag = 'div', style, blockStyle, wrapperProps, ...contextProps } = props; return ( - + {nodes.map((node, index) => ( (record[1], view.coverDefinition)?.[0] @@ -99,6 +100,31 @@ export async function RecordCard( )} > {view.columns.map((column) => { + const definition = block.data.definition[column]; + + if (!definition) { + return null; + } + + if (!view.hideColumnTitle && definition.title) { + const ariaLabelledBy = `${block.key}-${column}-title`; + return ( +
+
+ {definition.title} +
+ +
+ ); + } + return ; })} diff --git a/packages/gitbook/src/components/DocumentView/Table/RecordColumnValue.tsx b/packages/gitbook/src/components/DocumentView/Table/RecordColumnValue.tsx index 17046d0ad..064607523 100644 --- a/packages/gitbook/src/components/DocumentView/Table/RecordColumnValue.tsx +++ b/packages/gitbook/src/components/DocumentView/Table/RecordColumnValue.tsx @@ -22,11 +22,12 @@ import { FileIcon } from '../FileIcon'; export async function RecordColumnValue( props: BlockProps & { tag?: Tag; + ariaLabelledBy?: string; record: TableRecordKV; column: string; }, ) { - const { tag: Tag = 'div', block, document, record, column, context } = props; + const { tag: Tag = 'div', ariaLabelledBy, block, document, record, column, context } = props; const definition = block.data.definition[column]; const value = record[1].values[column]; @@ -42,6 +43,7 @@ export async function RecordColumnValue( className={tcls('w-5', 'h-5')} checked={value as boolean} disabled={true} + aria-labelledby={ariaLabelledBy} /> ); case 'rating': @@ -67,7 +69,8 @@ export async function RecordColumnValue( ( return ( {`${value}`} ); case 'text': @@ -116,6 +120,9 @@ export async function RecordColumnValue( ]} context={context} blockStyle={['w-full', 'max-w-[unset]']} + wrapperProps={{ + 'aria-labelledby': ariaLabelledBy, + }} /> ); case 'files': @@ -129,7 +136,7 @@ export async function RecordColumnValue( ); return ( - + {files.filter(filterOutNullable).map((ref, index) => { const contentType = ref.file ? getSimplifiedContentType(ref.file.contentType) @@ -178,7 +185,10 @@ export async function RecordColumnValue( }) : null; return ( - + {resolved?.icon ?? null} {resolved ? ( {resolved.text} @@ -197,7 +207,7 @@ export async function RecordColumnValue( ); return ( - + {resolved.filter(filterOutNullable).map((file, index) => ( {file.text} @@ -208,7 +218,7 @@ export async function RecordColumnValue( } case 'select': { return ( - + {(value as string[]).map((selectId) => { const option = definition.options.find(