Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
return;
}
var menuId = $"{Model.ContainerId}-menu";
var searchId = $"{Model.ContainerId}-search";
// Chips and menu entries drop the words every variant name shares (bedrock_secrets → bedrock); the full name stays as their tooltip.
var chipLabels = Model.UseChips ? ChipLabels.Shorten([.. Model.Variants.Select(static v => v.DisplayName)]) : [];
string ChipLabel(int i) => Model.Variants[i].IsArrayVariant ? $"{chipLabels[i]}[]" : chipLabels[i];
Expand Down Expand Up @@ -42,12 +43,13 @@
<span data-chip-more-label></span>
<svg width="12" height="12" viewBox="0 0 16 16" aria-hidden="true"><use href="#icon-chevron-down"/></svg>
</button>
@* A long list searches from the row itself: typing opens the menu with every match, so nobody has to open it first. *@
@* A long list searches from the row itself: typing opens the menu with every match, so nobody has to open it first.
The menu then sits under the search box (data-anchor, floating.ts). *@
@if (Model.HasFilter)
{
<input type="search" class="union-variant-search" data-chip-filter placeholder="Search variants" aria-label="Search variants" aria-controls="@menuId" autocomplete="off" />
<input type="search" id="@searchId" class="union-variant-search" data-chip-filter placeholder="Search variants" aria-label="Search variants" aria-controls="@menuId" autocomplete="off" />
}
<div id="@menuId" class="api-example-menu simple-scrollbar" popover="@(Model.HasFilter ? "manual" : "auto")" data-chip-menu>
<div id="@menuId" class="api-example-menu simple-scrollbar" popover="@(Model.HasFilter ? "manual" : "auto")"@(Model.HasFilter ? new HtmlString($" data-anchor=\"{System.Net.WebUtility.HtmlEncode(searchId)}\"") : HtmlString.Empty) data-chip-menu>
<div role="menu" aria-label="More variants">
@for (var i = 0; i < Model.Variants.Count; i++)
{
Expand Down
55 changes: 27 additions & 28 deletions src/Elastic.ApiExplorer/_Partials/_PageActions.cshtml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@inherits RazorSlice<Elastic.ApiExplorer.Infrastructure.ApiPageActionsModel>
@* Copy page with a menu of the page's Markdown and the spec download. A page with no Markdown export gets the download alone. *@
@* Copy page with a menu of the page's Markdown and the spec download. A page with no Markdown export gets the download alone.
The menu is a popover (top layer), placed beside the chevron by floating.ts. *@
@if (Model.MarkdownUrl is null)
{
if (Model.Spec is not null)
Expand All @@ -17,32 +18,30 @@
</svg>
<span class="api-page-actions-label">Copy page</span>
</button>
<details class="api-page-actions-dropdown nav-select-dropdown">
<summary class="api-page-actions-chevron" aria-label="More page actions" aria-haspopup="menu">
<span class="api-page-actions-chevron-icon" aria-hidden="true">
<svg viewBox="0 0 16 16"><use href="#icon-chevron-down"/></svg>
</span>
</summary>
<div class="api-page-actions-menu" role="menu">
<button type="button" class="api-page-actions-option" role="menuitem" data-copy-page="@Model.MarkdownUrl">
<svg class="api-page-actions-icon" xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true">
<path fill-rule="evenodd" clip-rule="evenodd" d="M6 1C5.44771 1 5 1.44772 5 2V10C5 10.5523 5.44772 11 6 11H14C14.5523 11 15 10.5523 15 10V2C15 1.44771 14.5523 1 14 1H6ZM6 2L14 2V10H6V2Z" fill="currentColor"/>
<path d="M2 5H4V6H2V14H10V12H11V14C11 14.5523 10.5523 15 10 15H2C1.44772 15 1 14.5523 1 14V6C1 5.44772 1.44771 5 2 5Z" fill="currentColor"/>
</svg>
Copy page
</button>
<a class="api-page-actions-option" role="menuitem" href="@Model.MarkdownUrl" target="_blank" rel="noopener" hx-boost="false">
<svg class="api-page-actions-icon" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 -1 24 24" aria-hidden="true">
<path fill="currentColor" d="M22.131725 19.247H1.9386225C1.0239525 19.247 0.25 18.47305 0.25 17.558375v-11.11675c0 -0.914675 0.7739525 -1.688625 1.6886225 -1.688625H22.061375c0.914675 0 1.688625 0.77395 1.688625 1.688625v11.11675c0 0.914675 -0.7036 1.688625 -1.618275 1.688625ZM1.9386225 5.87875c-0.2814375 0 -0.562875 0.281425 -0.562875 0.562875v11.11675c0 0.3518 0.2814375 0.562875 0.562875 0.562875H22.061375c0.3518 0 0.562875 -0.281425 0.562875 -0.562875v-11.11675c0 -0.3518 -0.281425 -0.562875 -0.562875 -0.562875l-20.1227525 0ZM3.62725 15.86975V8.130225h2.2515l2.2515 2.814375 2.251475 -2.814375h2.2515V15.86975h-2.2515V11.437125L8.13025 14.2515l-2.2515 -2.814375V15.86975h-2.2515Zm14.1422 0L14.392225 12.140725h2.251475v-4.0105h2.2515v3.940125h2.2515L17.76945 15.86975Z" stroke-width="0.25"></path>
</svg>
View as Markdown
</a>
@if (Model.Spec is not null)
{
<div class="api-menu-sep" role="separator"></div>
@await RenderPartialAsync(_SpecDownloadLinks.Create(Model.Spec))
}
</div>
</details>
<button type="button" class="api-page-actions-chevron" popovertarget="api-page-actions-menu" aria-label="More page actions" aria-haspopup="menu" aria-expanded="false">
<span class="api-page-actions-chevron-icon" aria-hidden="true">
<svg viewBox="0 0 16 16"><use href="#icon-chevron-down"/></svg>
</span>
</button>
</div>
<div id="api-page-actions-menu" class="api-page-actions-menu" role="menu" popover data-placement="bottom-end">
Comment thread
infra-vault-gh-plugin-prod[bot] marked this conversation as resolved.
Resolved
Comment thread
infra-vault-gh-plugin-prod[bot] marked this conversation as resolved.
Resolved
<button type="button" class="api-page-actions-option" role="menuitem" data-copy-page="@Model.MarkdownUrl">
<svg class="api-page-actions-icon" xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true">
<path fill-rule="evenodd" clip-rule="evenodd" d="M6 1C5.44771 1 5 1.44772 5 2V10C5 10.5523 5.44772 11 6 11H14C14.5523 11 15 10.5523 15 10V2C15 1.44771 14.5523 1 14 1H6ZM6 2L14 2V10H6V2Z" fill="currentColor"/>
<path d="M2 5H4V6H2V14H10V12H11V14C11 14.5523 10.5523 15 10 15H2C1.44772 15 1 14.5523 1 14V6C1 5.44772 1.44771 5 2 5Z" fill="currentColor"/>
</svg>
Copy page
</button>
<a class="api-page-actions-option" role="menuitem" href="@Model.MarkdownUrl" target="_blank" rel="noopener" hx-boost="false">
<svg class="api-page-actions-icon" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 -1 24 24" aria-hidden="true">
<path fill="currentColor" d="M22.131725 19.247H1.9386225C1.0239525 19.247 0.25 18.47305 0.25 17.558375v-11.11675c0 -0.914675 0.7739525 -1.688625 1.6886225 -1.688625H22.061375c0.914675 0 1.688625 0.77395 1.688625 1.688625v11.11675c0 0.914675 -0.7036 1.688625 -1.618275 1.688625ZM1.9386225 5.87875c-0.2814375 0 -0.562875 0.281425 -0.562875 0.562875v11.11675c0 0.3518 0.2814375 0.562875 0.562875 0.562875H22.061375c0.3518 0 0.562875 -0.281425 0.562875 -0.562875v-11.11675c0 -0.3518 -0.281425 -0.562875 -0.562875 -0.562875l-20.1227525 0ZM3.62725 15.86975V8.130225h2.2515l2.2515 2.814375 2.251475 -2.814375h2.2515V15.86975h-2.2515V11.437125L8.13025 14.2515l-2.2515 -2.814375V15.86975h-2.2515Zm14.1422 0L14.392225 12.140725h2.251475v-4.0105h2.2515v3.940125h2.2515L17.76945 15.86975Z" stroke-width="0.25"></path>
</svg>
View as Markdown
</a>
@if (Model.Spec is not null)
{
<div class="api-menu-sep" role="separator"></div>
@await RenderPartialAsync(_SpecDownloadLinks.Create(Model.Spec))
}
</div>
</div>
21 changes: 10 additions & 11 deletions src/Elastic.ApiExplorer/_Partials/_SpecDownloadActions.cshtml
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
@inherits RazorSlice<Elastic.Documentation.Site.ApiSpecDownload>
@* For a page with no Markdown export, so no Copy page: the spec download is the whole menu. *@
<div class="api-page-actions" role="group" aria-label="Page actions">
@* For a page with no Markdown export, so no Copy page: the spec download is the whole menu. Like Copy page's, the menu
is a popover placed beside its button by floating.ts. Without popover support the links show inline (api-docs.css). *@
<div class="api-page-actions api-page-actions--download-only" role="group" aria-label="Page actions">
<div class="api-page-actions-split">
<details class="api-page-actions-dropdown nav-select-dropdown">
<summary class="api-page-actions-chevron api-page-actions-chevron--labeled" aria-haspopup="menu">
@await RenderPartialAsync(_DownloadIcon.Create())
<span class="api-page-actions-label">Download spec</span>
</summary>
<div class="api-page-actions-menu" role="menu">
@await RenderPartialAsync(_SpecDownloadLinks.Create(Model))
</div>
</details>
<button type="button" class="api-page-actions-chevron api-page-actions-chevron--labeled" popovertarget="api-page-actions-menu" aria-haspopup="menu" aria-expanded="false">
@await RenderPartialAsync(_DownloadIcon.Create())
<span class="api-page-actions-label">Download spec</span>
</button>
</div>
<div id="api-page-actions-menu" class="api-page-actions-menu" role="menu" popover data-placement="bottom-end">
@await RenderPartialAsync(_SpecDownloadLinks.Create(Model))
</div>
</div>
39 changes: 17 additions & 22 deletions src/Elastic.Documentation.Site/Assets/api-docs.css
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,9 @@
padding: 0;
border-left: 1px solid #cad3e2;
border-radius: 0 7px 7px 0;
list-style: none;
}

/* No Copy page beside it, so the summary is the whole control. */
/* No Copy page beside it, so the button is the whole control. */
.api-page-actions-chevron--labeled {
width: auto;
gap: 8px;
Expand All @@ -260,10 +259,6 @@
white-space: nowrap;
}

.api-page-actions-chevron::-webkit-details-marker {
display: none;
}

.api-page-actions-button:hover,
.api-page-actions-chevron:hover {
background: #f6f9fc;
Expand Down Expand Up @@ -292,28 +287,28 @@
height: 12px;
}

.api-page-actions details.api-page-actions-dropdown,
.api-page-actions details.nav-select-dropdown {
position: relative;
display: flex;
width: auto;
overflow: visible;
.api-page-actions-chevron[aria-expanded='true'] .api-page-actions-chevron-icon {
transform: rotate(180deg);
}

.api-page-actions-dropdown[open] .api-page-actions-chevron-icon,
.api-page-actions-dropdown.is-open .api-page-actions-chevron-icon {
transform: rotate(180deg);
/* Without the Popover API (floating.css hides the menu) the download-only page has nothing else on it, so its links show inline in place of the button. */
@supports not selector(:popover-open) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Severity: P3 (Low)

The updated snapshot verifies the modifier class, but it cannot catch a CSS regression that hides both download links when popovers are unsupported. Add a browser-level check for the download-only fallback that verifies the trigger is hidden and both links remain visible.

Generated by Libra. React with 👍 or 👎 to give feedback on this comment.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No new test, but I ran the check you describe against the shipped CSS in Chrome. I took every rule from the built @supports not selector(:popover-open) blocks, including floating.css's [popover] { display: none }, and applied them unwrapped to a page whose menu keeps its popover attribute, so the two rules compete as they would in a browser without the API. On a download-only page the trigger is hidden and both download links are visible at 375px. On the Copy page variant the menu stays hidden. The fallback wins on specificity, since both stylesheets are unlayered. I did not add this to the repo because neither harness can turn the Popover API off. The journey language has no way to do it, and the visual suite only compares screenshots. A test would have to unwrap the rules itself, so it would re-check my emulation, not the browser. For a path only browsers older than 2024 reach, I think that is not worth a new test setup. Say so if you want one anyway.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don’t think a bespoke test setup is warranted for this low-severity fallback. Your check is useful evidence that the current rules produce the intended result: the download-only split control is hidden while its menu is displayed under the @supports not selector(:popover-open) fallback (api-docs.css), alongside the rule that hides [popover] elements without the API (floating.css). It isn’t durable regression coverage or a run in an unsupported browser, but given the harness limitation and the age-limited path, I wouldn’t ask you to add a custom emulation test.

Generated by Libra. React with 👍 or 👎 to give feedback on this comment.

.api-page-actions--download-only .api-page-actions-split {
display: none;
}
.api-page-actions--download-only .api-page-actions-menu {
display: block;
}
}

/* A popover placed beside the chevron by floating.ts (floating.css). */
.api-page-actions-menu {
box-sizing: border-box;
position: absolute;
top: calc(100% + 6px);
right: 0;
z-index: 40;
width: max-content;
min-width: 196px;
margin: 0;
max-width: calc(100vw - 16px);
max-height: var(--floating-available-height, none);
overflow-y: auto;
padding: 8px;
background: #fff;
border: 0;
Expand Down Expand Up @@ -3823,12 +3818,12 @@ html:has(.api-page-shell) {
fill: currentColor;
}

/* Positioned from the "more" button in api-examples-carousel.ts; the popover UA styles centre it otherwise. */
/* A popover placed under the "more" button, or the row's search box, by floating.ts (floating.css). */
.api-example-menu {
box-sizing: border-box;
width: max-content;
max-width: min(320px, calc(100vw - 16px));
max-height: min(320px, 50vh);
max-height: min(320px, 50vh, var(--floating-available-height, 100vh));
margin: 0;
padding: 4px;
overflow: auto;
Expand Down
6 changes: 2 additions & 4 deletions src/Elastic.Documentation.Site/Assets/api-docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -706,10 +706,8 @@ export function initApiPageActions(): void {

event.preventDefault()
const root = trigger.closest('.api-page-actions')
const dropdown = root?.querySelector<HTMLDetailsElement>(
'.api-page-actions-dropdown'
)
if (dropdown) dropdown.open = false
const menu = trigger.closest<HTMLElement>('[popover]')
if (menu?.matches(':popover-open')) menu.hidePopover()
void copyPageMarkdown(trigger.dataset.copyPage, root).catch((error) => {
console.error(error)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,22 @@ describe('API examples chip overflow', () => {
expect(visibleItems()).not.toContain('d')
})

it('moves the focus into the menu only once it is placed, since it is hidden before', () => {
initApiExamples()
const menu = document.querySelector<HTMLElement>('[data-example-menu]')!
const toggle = new Event('toggle') as ToggleEvent
Object.defineProperty(toggle, 'newState', { value: 'open' })

menu.dispatchEvent(toggle)
expect(document.activeElement).toBe(document.body)

menu.dispatchEvent(new Event('floating:placed', { bubbles: true }))
// The menu has a filter field, which takes the focus before any item does.
expect(document.activeElement).toBe(
document.querySelector('[data-example-filter]')
)
})

it('filters the menu fuzzily, forgiving a typo and ranking the best match first', () => {
initApiExamples()
const input = document.querySelector<HTMLInputElement>(
Expand All @@ -796,37 +812,6 @@ describe('API examples chip overflow', () => {

expect(visibleItems()).toEqual(['d', 'e'])
})

it('keeps the open menu under its button while the page scrolls', async () => {
initApiExamples()
const more = document.querySelector<HTMLElement>('[data-example-more]')!
const menu = document.querySelector<HTMLElement>('[data-example-menu]')!
let top = 100
more.getBoundingClientRect = () =>
({ top, bottom: top + 24, left: 50, width: 80 }) as DOMRect
menu.getBoundingClientRect = () =>
({ width: 200, height: 100 }) as DOMRect

const toggle = new Event('toggle') as ToggleEvent
Object.defineProperty(toggle, 'newState', { value: 'open' })
menu.dispatchEvent(toggle)
expect(menu.style.top).toBe('128px')

const frame = () =>
new Promise((resolve) => requestAnimationFrame(resolve))
top = 40
window.dispatchEvent(new Event('scroll'))
await frame()
expect(menu.style.top).toBe('68px')

const close = new Event('toggle') as ToggleEvent
Object.defineProperty(close, 'newState', { value: 'closed' })
menu.dispatchEvent(close)
top = 10
window.dispatchEvent(new Event('scroll'))
await frame()
expect(menu.style.top).toBe('68px')
})
})

describe('syncStripHeight', () => {
Expand Down
28 changes: 4 additions & 24 deletions src/Elastic.Documentation.Site/Assets/api-identity.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* The API identity at the top of the API sidebar: product and version in one trigger and one menu.
* Used on API pages in the current layout, so nothing here is scoped to body.navigation-preview.
* The menu is a popover placed by api-menu.ts; the rows reuse .secondary-nav-dropdown-link from
* The menu is a popover placed by floating.ts; the rows reuse .secondary-nav-dropdown-link from
* secondary-nav-dropdown.css.
*/

Expand Down Expand Up @@ -109,17 +109,12 @@
background: #eeeff1;
}

/*
* Menus. A popover sits in the top layer, so no ancestor can clip it. Floating UI sets
* left/top (api-menu.ts); everything the browser puts on [popover] is reset here.
*/
/* Menus. floating.ts places the popover beside its button (floating.css). */
.api-menu {
position: fixed;
inset: auto;
box-sizing: border-box;
min-width: 160px;
min-width: max(160px, var(--floating-anchor-width, 0px));
max-width: min(20rem, calc(100vw - 16px));
margin: 0;
max-height: max(120px, var(--floating-available-height, 100vh));
padding: 8px;
overflow-y: auto;
border: 0;
Expand All @@ -134,21 +129,6 @@
filter: drop-shadow(0 0 2px rgb(43 57 79 / 0.16))
drop-shadow(0 3px 10px rgb(43 57 79 / 0.1))
drop-shadow(0 6px 14px rgb(43 57 79 / 0.06));
transition: opacity 0.15s ease;
}
/* Hidden until api-menu.ts has placed it, so it never flashes at the wrong spot. */
.api-menu:not([data-placed]) {
visibility: hidden;
}
@starting-style {
.api-menu:popover-open {
opacity: 0;
}
}
@media (prefers-reduced-motion: reduce) {
.api-menu {
transition: none;
}
}

/* The version sits beside the name, on its first line. A long name wraps and the version stays put. */
Expand Down
Loading
Loading