mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 18:31:06 +00:00
chore: lift components folder
This commit is contained in:
parent
76df51674d
commit
2200b29b92
301 changed files with 57 additions and 76 deletions
44
src/ListBox/ListBoxField.svelte
Normal file
44
src/ListBox/ListBoxField.svelte
Normal file
|
@ -0,0 +1,44 @@
|
|||
<script>
|
||||
export const translationIds = { close: "close", open: "open" };
|
||||
export let disabled = false;
|
||||
export let id = "ccs-" + Math.random().toString(36);
|
||||
export let role = "combobox";
|
||||
export let tabindex = "-1";
|
||||
export let translateWithId = id => defaultTranslations[id];
|
||||
export let ref = null;
|
||||
|
||||
import { getContext } from "svelte";
|
||||
|
||||
const defaultTranslations = {
|
||||
[translationIds.close]: "Close menu",
|
||||
[translationIds.open]: "Open menu"
|
||||
};
|
||||
const ctx = getContext("MultiSelect");
|
||||
|
||||
$: if (ctx && ref) {
|
||||
ctx.declareRef({ key: "field", ref });
|
||||
}
|
||||
|
||||
$: ariaExpanded = $$props["aria-expanded"];
|
||||
$: menuId = `menu-${id}`;
|
||||
</script>
|
||||
|
||||
<div
|
||||
bind:this={ref}
|
||||
role={ariaExpanded ? 'combobox' : role}
|
||||
aria-expanded={ariaExpanded}
|
||||
aria-owns={(ariaExpanded && menuId) || undefined}
|
||||
aria-controls={(ariaExpanded && menuId) || undefined}
|
||||
aria-disabled={disabled}
|
||||
aria-label={ariaExpanded ? translateWithId('close') : translateWithId('open')}
|
||||
tabindex={disabled ? '-1' : tabindex}
|
||||
class:bx--list-box__field={true}
|
||||
{...$$restProps}
|
||||
on:click
|
||||
on:mouseover
|
||||
on:mouseenter
|
||||
on:mouseleave
|
||||
on:keydown|preventDefault|stopPropagation
|
||||
on:blur>
|
||||
<slot />
|
||||
</div>
|
Loading…
Add table
Add a link
Reference in a new issue