feat(UIShell): export ref for all UIShell components

This commit is contained in:
josefaidt 2020-10-01 15:13:40 -05:00
commit d1e9fc7225
11 changed files with 82 additions and 5 deletions

View file

@ -36,6 +36,12 @@
*/ */
export let platformName = undefined; export let platformName = undefined;
/**
* Obtain a reference to the HTML button element
* @type {null | HTMLButtonElement} [ref=null]
*/
export let ref = null;
import HamburgerMenu from "../SideNav/HamburgerMenu.svelte"; import HamburgerMenu from "../SideNav/HamburgerMenu.svelte";
let winWidth = undefined; let winWidth = undefined;
@ -53,7 +59,13 @@
{#if winWidth < 1056} {#if winWidth < 1056}
<HamburgerMenu bind:isOpen="{isSideNavOpen}" /> <HamburgerMenu bind:isOpen="{isSideNavOpen}" />
{/if} {/if}
<a href="{href}" class:bx--header__name="{true}" {...$$restProps} on:click> <a
href="{href}"
class:bx--header__name="{true}"
bind:this="{ref}"
{...$$restProps}
on:click
>
{#if company} {#if company}
<span class:bx--header__name--prefix="{true}">{company}&nbsp;</span> <span class:bx--header__name--prefix="{true}">{company}&nbsp;</span>
{/if} {/if}

View file

@ -17,6 +17,12 @@
*/ */
export let icon = undefined; export let icon = undefined;
/**
* Obtain a reference to the HTML button element
* @type {null | HTMLButtonElement} [ref=null]
*/
export let ref = null;
import { Icon } from "../../Icon"; import { Icon } from "../../Icon";
</script> </script>
@ -31,6 +37,7 @@
</style> </style>
<a <a
bind:this="{ref}"
class:bx--header__action="{true}" class:bx--header__action="{true}"
class:bx--header__action--active="{linkIsActive}" class:bx--header__action--active="{linkIsActive}"
class:action-link="{true}" class:action-link="{true}"

View file

@ -10,10 +10,17 @@
* @type {string} [text] * @type {string} [text]
*/ */
export let text = undefined; export let text = undefined;
/**
* Obtain a reference to the HTML button element
* @type {null | HTMLButtonElement} [ref=null]
*/
export let ref = null;
</script> </script>
<li> <li>
<a <a
bind:this="{ref}"
role="menuitem" role="menuitem"
tabindex="0" tabindex="0"
href="{href}" href="{href}"

View file

@ -17,6 +17,12 @@
*/ */
export let text = undefined; export let text = undefined;
/**
* Obtain a reference to the HTML button element
* @type {null | HTMLButtonElement} [ref=null]
*/
export let ref = null;
/** /**
* Specify the ARIA label for the chevron icon * Specify the ARIA label for the chevron icon
* @type {string} [iconDescription="Expand/Collapse"] * @type {string} [iconDescription="Expand/Collapse"]
@ -24,8 +30,6 @@
export let iconDescription = "Expand/Collapse"; export let iconDescription = "Expand/Collapse";
import ChevronDown16 from "carbon-icons-svelte/lib/ChevronDown16"; import ChevronDown16 from "carbon-icons-svelte/lib/ChevronDown16";
let ref = null;
</script> </script>
<svelte:window <svelte:window

View file

@ -4,10 +4,22 @@
* @type {string} [href] * @type {string} [href]
*/ */
export let href = undefined; export let href = undefined;
/**
* Obtain a reference to the HTML button element
* @type {null | HTMLButtonElement} [ref=null]
*/
export let ref = null;
</script> </script>
<li class:bx--switcher__item="{true}"> <li class:bx--switcher__item="{true}">
<a href="{href}" class:bx--switcher__item-link="{true}" {...$$restProps} on:click> <a
bind:this="{ref}"
href="{href}"
class:bx--switcher__item-link="{true}"
{...$$restProps}
on:click
>
<slot /> <slot />
</a> </a>
</li> </li>

View file

@ -20,7 +20,7 @@
<button <button
type="button" type="button"
ref="{ref}" bind:this="{ref}"
class:bx--header__action="{true}" class:bx--header__action="{true}"
class:bx--header__action--active="{isActive}" class:bx--header__action--active="{isActive}"
{...$$restProps} {...$$restProps}

View file

@ -11,6 +11,12 @@
*/ */
export let isOpen = false; export let isOpen = false;
/**
* Obtain a reference to the HTML button element
* @type {null | HTMLButtonElement} [ref=null]
*/
export let ref = null;
import { fly } from "svelte/transition"; import { fly } from "svelte/transition";
import Close20 from "carbon-icons-svelte/lib/Close20"; import Close20 from "carbon-icons-svelte/lib/Close20";
import Menu20 from "carbon-icons-svelte/lib/Menu20"; import Menu20 from "carbon-icons-svelte/lib/Menu20";
@ -19,6 +25,7 @@
<button <button
type="button" type="button"
bind:this="{ref}"
title="Open menu" title="Open menu"
aria-label="{ariaLabel}" aria-label="{ariaLabel}"
class:bx--header__action="{true}" class:bx--header__action="{true}"

View file

@ -16,6 +16,12 @@
* @type {boolean} [isOpen=false] * @type {boolean} [isOpen=false]
*/ */
export let isOpen = false; export let isOpen = false;
/**
* Obtain a reference to the HTML button element
* @type {null | HTMLButtonElement} [ref=null]
*/
export let ref = null;
</script> </script>
{#if fixed} {#if fixed}
@ -28,6 +34,7 @@
></div> ></div>
{/if} {/if}
<nav <nav
bind:this="{ref}"
aria-label="{ariaLabel}" aria-label="{ariaLabel}"
class:bx--side-nav__navigation="{true}" class:bx--side-nav__navigation="{true}"
class:bx--side-nav="{true}" class:bx--side-nav="{true}"

View file

@ -23,11 +23,18 @@
*/ */
export let icon = undefined; export let icon = undefined;
/**
* Obtain a reference to the HTML button element
* @type {null | HTMLButtonElement} [ref=null]
*/
export let ref = null;
import { Icon } from "../../Icon"; import { Icon } from "../../Icon";
</script> </script>
<li class:bx--side-nav__item="{true}"> <li class:bx--side-nav__item="{true}">
<a <a
bind:this="{ref}"
aria-current="{isSelected ? 'page' : undefined}" aria-current="{isSelected ? 'page' : undefined}"
href="{href}" href="{href}"
class:bx--side-nav__link="{true}" class:bx--side-nav__link="{true}"

View file

@ -17,6 +17,12 @@
*/ */
export let icon = undefined; export let icon = undefined;
/**
* Obtain a reference to the HTML button element
* @type {null | HTMLButtonElement} [ref=null]
*/
export let ref = null;
import ChevronDown16 from "carbon-icons-svelte/lib/ChevronDown16"; import ChevronDown16 from "carbon-icons-svelte/lib/ChevronDown16";
import { Icon } from "../../Icon"; import { Icon } from "../../Icon";
</script> </script>
@ -24,6 +30,7 @@
<li class:bx--side-nav__item="{true}" class:bx--side-nav__item--icon="{icon}"> <li class:bx--side-nav__item="{true}" class:bx--side-nav__item--icon="{icon}">
<button <button
type="button" type="button"
bind:this="{ref}"
aria-expanded="{expanded}" aria-expanded="{expanded}"
class:bx--side-nav__submenu="{true}" class:bx--side-nav__submenu="{true}"
{...$$restProps} {...$$restProps}

View file

@ -16,10 +16,17 @@
* @type {string} [text] * @type {string} [text]
*/ */
export let text = undefined; export let text = undefined;
/**
* Obtain a reference to the HTML button element
* @type {null | HTMLButtonElement} [ref=null]
*/
export let ref = null;
</script> </script>
<li class:bx--side-nav__menu-item="{true}"> <li class:bx--side-nav__menu-item="{true}">
<a <a
bind:this="{ref}"
aria-current="{isSelected ? 'page' : undefined}" aria-current="{isSelected ? 'page' : undefined}"
href="{href}" href="{href}"
class:bx--side-nav__link="{true}" class:bx--side-nav__link="{true}"