Skip to content

Commit c219612

Browse files
committed
experiment: Use semantic table to show line numbers to assistive technology
1 parent 271e3cf commit c219612

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/code-view/internal.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export function InternalCodeView({
6666
>
6767
<div className={styles["scroll-container"]} ref={containerRef}>
6868
<table
69-
role="presentation"
69+
role={lineNumbers ? "table" : "presentation"}
7070
className={clsx(
7171
styles["code-table"],
7272
actions && styles["code-table-with-actions"],
@@ -77,12 +77,20 @@ export function InternalCodeView({
7777
<col style={{ width: 1 } /* shrink to fit content */} />
7878
<col style={{ width: "auto" }} />
7979
</colgroup>
80+
{lineNumbers && (
81+
<thead className={styles["table-header"]}>
82+
<tr>
83+
<th>Row number</th>
84+
<th>Content</th>
85+
</tr>
86+
</thead>
87+
)}
8088
<tbody>
8189
{Children.map(codeElement.props.children, (child, index) => {
8290
return (
8391
<tr key={index}>
8492
{lineNumbers && (
85-
<td className={clsx(styles["line-number"], styles.unselectable)} aria-hidden={true}>
93+
<td className={clsx(styles["line-number"], styles.unselectable)}>
8694
<Box variant="code" color="text-status-inactive" fontSize="body-m">
8795
{index + 1}
8896
</Box>

src/code-view/styles.scss

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ $color-background-code-view-dark: #282c34;
1414
border-start-end-radius: cs.$border-radius-tiles;
1515
border-end-start-radius: cs.$border-radius-tiles;
1616
border-end-end-radius: cs.$border-radius-tiles;
17-
17+
1818
background-color: $color-background-code-view-light;
1919
:global(.awsui-dark-mode) &,
2020
:global(.awsui-polaris-dark-mode) & {
@@ -43,6 +43,12 @@ $color-background-code-view-dark: #282c34;
4343
padding-inline-end: cs.$space-static-xxl;
4444
}
4545

46+
.table-header {
47+
position: absolute;
48+
inset-block-start: -9999px;
49+
inset-inline-start: -9999px;
50+
}
51+
4652
.line-number {
4753
vertical-align: text-top;
4854
white-space: nowrap;

0 commit comments

Comments
 (0)