This commit is contained in:
Bilux 2023-05-19 01:32:27 +00:00 committed by GitHub
commit 30ed49d0dc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 40 additions and 2 deletions

View file

@ -126,6 +126,9 @@
/** Set to `number` to set current page */ /** Set to `number` to set current page */
export let page = 0; export let page = 0;
/** Obtain a reference to the trigger body element */
export let tRef = null;
import { createEventDispatcher, setContext } from "svelte"; import { createEventDispatcher, setContext } from "svelte";
import { writable } from "svelte/store"; import { writable } from "svelte/store";
import ChevronRight from "../icons/ChevronRight.svelte"; import ChevronRight from "../icons/ChevronRight.svelte";
@ -258,7 +261,7 @@
}; };
</script> </script>
<TableContainer useStaticWidth="{useStaticWidth}" {...$$restProps}> <TableContainer bind:ref={tRef} useStaticWidth="{useStaticWidth}" {...$$restProps}>
{#if title || $$slots.title || description || $$slots.description} {#if title || $$slots.title || description || $$slots.description}
<div class:bx--data-table-header="{true}"> <div class:bx--data-table-header="{true}">
{#if title || $$slots.title} {#if title || $$slots.title}

View file

@ -10,9 +10,13 @@
/** Set to `true` to use static width */ /** Set to `true` to use static width */
export let useStaticWidth = false; export let useStaticWidth = false;
/** Obtain a reference to the Div HTML element */
export let ref = null;
</script> </script>
<div <div
bind:this={ref}
class:bx--data-table-container="{true}" class:bx--data-table-container="{true}"
class:bx--data-table-container--static="{useStaticWidth}" class:bx--data-table-container--static="{useStaticWidth}"
class:bx--data-table--max-width="{stickyHeader}" class:bx--data-table--max-width="{stickyHeader}"

View file

@ -49,6 +49,9 @@
/** Set an id for the button element */ /** Set an id for the button element */
export let id = "ccs-" + Math.random().toString(36); export let id = "ccs-" + Math.random().toString(36);
/** Obtain a reference to the trigger parent element */
export let parentRef = null;
/** Obtain a reference to the trigger button element */ /** Obtain a reference to the trigger button element */
export let buttonRef = null; export let buttonRef = null;
@ -128,10 +131,20 @@
} }
if (open) { if (open) {
const { width, height } = buttonRef.getBoundingClientRect(); const { width, height, bottom } = buttonRef.getBoundingClientRect();
buttonWidth = width; buttonWidth = width;
// if menu height is bigger than the offset then flip the direction to top
if (parentRef) {
if (
menuRef.getBoundingClientRect().height >
parentRef.getBoundingClientRect().bottom - bottom
) {
direction = "top";
}
}
if (!onMountAfterUpdate && $currentIndex < 0) { if (!onMountAfterUpdate && $currentIndex < 0) {
menuRef.focus(); menuRef.focus();
} }

View file

@ -176,6 +176,12 @@ export interface DataTableProps
* @default 0 * @default 0
*/ */
page?: number; page?: number;
/**
* Obtain a reference to the TableContainer Div HTML element
* @type {null | HTMLDivElement}
*/
tref?: null | HTMLDivElement;
} }
export default class DataTable extends SvelteComponentTyped< export default class DataTable extends SvelteComponentTyped<

View file

@ -26,6 +26,12 @@ export interface TableContainerProps
* @default false * @default false
*/ */
useStaticWidth?: boolean; useStaticWidth?: boolean;
/**
* Obtain a reference to the Div HTML element
* @type {null | HTMLDivElement}
*/
ref?: null | HTMLDivElement;
} }
export default class TableContainer extends SvelteComponentTyped< export default class TableContainer extends SvelteComponentTyped<

View file

@ -75,6 +75,12 @@ export interface OverflowMenuProps
* @default null * @default null
*/ */
menuRef?: null | HTMLUListElement; menuRef?: null | HTMLUListElement;
/**
* Obtain a reference to the trigger parent element
* @default null
*/
parentRef?: null | HTMLElement;
} }
export default class OverflowMenu extends SvelteComponentTyped< export default class OverflowMenu extends SvelteComponentTyped<