Skip to content
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 TOC header and card list roles in docs #9971

Merged
merged 2 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 11 additions & 19 deletions docfiles/tocheader.html
Original file line number Diff line number Diff line change
@@ -1,26 +1,18 @@
<div id="top-bar" class="ui fixed accent borderless @tocclass@ main menu hideprint docs" role="menubar">
<div>
<div class="docs-top-bar @tocclass@">
<div id="top-bar" class="menu-bar" role="menubar">
@sidebarToggle@
<div class="item" role="menuitem">
<div class="header-org-logo">
<img src="/static/logo/Microsoft_logo_rgb_W-white_D.png" alt="Microsoft">
</div>
<div class="header-org-logo-sm">
<img src="/static/logo/Microsoft_logo_rgb_W-white_D-square.png" alt="Microsoft">
</div>
<div class="header-title"><span>@orgtitle@</span></div>
<div class="logo-group" role="menuitem">
<img class="desktop-only" src="/static/logo/Microsoft_logo_rgb_W-white_D.png" alt="Microsoft">
<img class="desktop-hidden" src="/static/logo/Microsoft_logo_rgb_W-white_D-square.png" alt="Microsoft">
<div class="header-title desktop-only"><span>@orgtitle@</span></div>
</div>
</div>
<div>
<div class="item">
<form id="tocsearch1" class="search" role="form" method="get" action="https://www.bing.com/search">
<div class="ui fluid icon input">
<input type="hidden" name="q1" value="site:@homeurl@" />
@searchBar1@
</div>
</form>
<form id="tocsearch1" class="search" method="get" action="https://www.bing.com/search">
<div class="ui fluid icon input">
<input type="hidden" name="q1" value="site:@homeurl@" />
@searchBar1@
</div>
</div>
</form>
</div>

<div id="side-menu" class="ui vertical accent @tocclass@ sidebar menu left hideprint docs" role="menubar">
Expand Down
10 changes: 8 additions & 2 deletions pxtblocks/codecardRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { render } from "./render";
export interface CodeCardRenderOptions {
hideHeader?: boolean;
shortName?: boolean;
role?: string;
}

export function renderCodeCard(card: pxt.CodeCard, options: CodeCardRenderOptions = {}): HTMLElement {
Expand All @@ -22,8 +23,13 @@ export function renderCodeCard(card: pxt.CodeCard, options: CodeCardRenderOption
const style = card.style || "card";
let r = div(null, 'ui ' + style + ' ' + (card.color || '') + (link ? ' link' : ''), link ? "a" : "div");

r.setAttribute("role", "option");
r.setAttribute("aria-selected", "true");
if (options.role) {
r.setAttribute("role", options.role);
}

if (options.role === "option") {
r.setAttribute("aria-selected", "true");
}

if (link) {
const rAsLink = r as HTMLAnchorElement;
Expand Down
36 changes: 23 additions & 13 deletions pxtrunner/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -875,25 +875,30 @@ function renderApisAsync(options: ClientRenderOptions, replaceParent: boolean):
return l.name.localeCompare(r.name);
})

const ul = $('<div />').addClass('ui divided items');
ul.attr("role", "listbox");
const ul = document.createElement("div");
ul.className = "ui divided items";
ul.setAttribute("role", "list");
csymbols.forEach(symbol => addSymbolCardItem(ul, symbol, "item"));
if (replaceParent) c = c.parent();
c.replaceWith(ul)
})
});
}

function addCardItem(ul: JQuery, card: pxt.CodeCard) {
function addCardItem(ul: Element, card: pxt.CodeCard) {
if (!card) return;
const mC = /^\/(v\d+)/.exec(card.url);
const mP = /^\/(v\d+)/.exec(window.location.pathname);
const inEditor = /#doc/i.test(window.location.href);
if (card.url && !mC && mP && !inEditor) card.url = `/${mP[1]}/${card.url}`;
ul.append(renderCodeCard(card, { hideHeader: true, shortName: true }));

const listItem = document.createElement("div");
listItem.setAttribute("role", "listitem");
listItem.append(renderCodeCard(card, { hideHeader: true, shortName: true }));
ul.append(listItem);
}

function addSymbolCardItem(ul: JQuery, symbol: pxtc.SymbolInfo, cardStyle?: string) {
function addSymbolCardItem(ul: Element, symbol: pxtc.SymbolInfo, cardStyle?: string) {
const attributes = symbol.attributes;
const block = !attributes.blockHidden && Blockly.Blocks[attributes.blockId];
const card = block?.codeCard;
Expand All @@ -920,8 +925,9 @@ function renderLinksAsync(options: ClientRenderOptions, cls: string, replacePare
if (!cjs) return;
const file = cjs.getSourceFile(pxt.MAIN_TS);
const stmts = file.statements.slice(0);
const ul = $('<div />').addClass('ui cards');
ul.attr("role", "listbox");
const ul = document.createElement("div");
ul.setAttribute("role", "list");
ul.className = "card-list";
stmts.forEach(stmt => {
const kind = stmt.kind;
const info = decompileCallInfo(stmt);
Expand Down Expand Up @@ -1057,17 +1063,21 @@ function fillCodeCardAsync(c: JQuery, cards: pxt.CodeCard[], options: CodeCardRe
c.replaceWith(cc);
} else {
let cd = document.createElement("div")
cd.className = "ui cards";
cd.setAttribute("role", "listbox")
cd.className = "card-list";
cd.setAttribute("role", "list")
cards.forEach(card => {
// patch card url with version if necessary, we don't do this in the editor because that goes through the backend and passes the targetVersion then
const mC = /^\/(v\d+)/.exec(card.url);
const mP = /^\/(v\d+)/.exec(window.location.pathname);
const inEditor = /#doc/i.test(window.location.href);
if (card.url && !mC && mP && !inEditor) card.url = `/${mP[1]}${card.url}`;
const cardEl = renderCodeCard(card, options);
cd.appendChild(cardEl)
// automitcally display package icon for approved packages

const outer = document.createElement("div");
outer.setAttribute("role", "listitem");
outer.appendChild(cardEl);
cd.appendChild(outer)
// automatically display package icon for approved packages
if (card.cardType == "package") {
const repoId = pxt.github.parseRepoId((card.url || "").replace(/^\/pkg\//, ''));
if (repoId) {
Expand All @@ -1081,13 +1091,13 @@ function fillCodeCardAsync(c: JQuery, cards: pxt.CodeCard[], options: CodeCardRe
// update card info
card.imageUrl = pxt.github.mkRepoIconUrl(repoId);
// inject
cd.insertBefore(renderCodeCard(card, options), cardEl);
outer.insertBefore(renderCodeCard(card, options), cardEl);
cardEl.remove();
break;
}
})
.catch(e => {
// swallow
// ignore
pxt.reportException(e);
pxt.debug(`failed to load repo ${card.url}`)
})
Expand Down
52 changes: 13 additions & 39 deletions theme/docs.less
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@import "./docs/tocheader.less";

/*******************************
Docs
*******************************/
Expand Down Expand Up @@ -30,7 +32,6 @@

#docs .footer,
#docs .topbar,
.ui.menu.fixed.docs,
#docs {
top: auto;
background: hsl(@docsHue, 25%, 85%);
Expand Down Expand Up @@ -188,6 +189,17 @@
}
}

.card-list {
display: flex;
flex-wrap: wrap;
row-gap: 1.5rem;
column-gap: 1rem;

div .ui.card {
height: 100%;
}
}

/* Breadcrumb */
.ui.breadcrumb .divider {
color: black;
Expand Down Expand Up @@ -452,44 +464,6 @@
color: @docsLinkColor;
}

#top-bar {
.header-org-logo img,
.header-org-logo-sm img {
height: 1.4rem;
}

.header-org-logo-sm {
display: none;
}

.header-title:before {
content: "";
position: relative;
height: 1.5rem;
border-left: 2px solid #fff;
margin: 0.75rem;
}

.header-title span {
margin: 0.5rem;
font-size: 18px;
font-weight: 700;
}
}

@media only screen and (max-width: 767px) {
#top-bar {
.header-org-logo,
.header-title {
display: none;
}

.header-org-logo-sm {
display: block;
}
}
}

.replaceDocsAvatar() when not (@docsAvatarImage = none) {
#docs {
.avatar .avatar-image {
Expand Down
88 changes: 88 additions & 0 deletions theme/docs/tocheader.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
.docs-top-bar {
height: 3.5rem;
width: 100%;
display: flex;
flex-direction: row;

position: fixed;
top: 0;
z-index: 99999;

background: hsl(@docsHue, 25%, 85%);
&.inverted {
background: hsl(@docsHue, 15%, 20%);
}

.menu-bar {
display: flex;
flex-direction: row;
flex-grow: 1;

height: 100%;
align-items: center;
}

.logo-group {
display: flex;
flex-direction: row;
flex-grow: 1;
align-items: center;

padding-left: 1rem;
padding-right: 1rem;

img {
height: 1.4rem;
}
}

.header-title {
display: flex;
align-items: center;
padding-left: 0.5rem;

span {
color: white;
margin: 0.5rem;
font-size: 18px;
font-weight: 700;
}
}

.header-title::before {
content: "";
position: relative;
height: 1.5rem;
border-left: 2px solid #fff;
margin: 0.75rem;
}

.launch.item.icon {
width: 3.5rem;
height: 3.5rem;
background: transparent;
display: flex;
align-items: center;
justify-content: center;
color: white;
line-height: 1;

cursor: pointer;

&:hover {
background: hsla(0,0%,100%,.1);
text-decoration: none;
}
}

.search {
display: flex;
align-items: center;
margin-right: 1rem;

div.input {
min-width: 14em;
height: 2.5em;
}
}
}