mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 10:21:05 +00:00
parent
d55aacaf27
commit
76d7dc5319
9 changed files with 190 additions and 0 deletions
32
src/components/ListBox/ListBoxField.svelte
Normal file
32
src/components/ListBox/ListBoxField.svelte
Normal file
|
@ -0,0 +1,32 @@
|
|||
<script>
|
||||
let className = undefined;
|
||||
export { className as class };
|
||||
export let id = Math.random();
|
||||
export let tabindex = '-1';
|
||||
export let role = 'combobox';
|
||||
export let disabled = false;
|
||||
export const translationIds = { close: 'close', open: 'open' };
|
||||
export let translateWithId = id => defaultTranslations[id];
|
||||
export let style = undefined;
|
||||
|
||||
import { cx } from '../../lib';
|
||||
|
||||
const defaultTranslations = {
|
||||
[translationIds.close]: 'Close menu',
|
||||
[translationIds.open]: 'Open menu'
|
||||
};
|
||||
|
||||
$: ariaExpanded = $$props['aria-expanded'];
|
||||
$: menuId = `menu-${id}`;
|
||||
</script>
|
||||
|
||||
<div
|
||||
role={ariaExpanded ? 'combobox' : role}
|
||||
aria-owns={(ariaExpanded && menuId) || undefined}
|
||||
aria-controls={(ariaExpanded && menuId) || undefined}
|
||||
aria-label={ariaExpanded ? translateWithId('close') : translateWithId('open')}
|
||||
tabindex={disabled ? '-1' : tabindex}
|
||||
class={cx('--list-box__field', className)}
|
||||
{style}>
|
||||
<slot />
|
||||
</div>
|
Loading…
Add table
Add a link
Reference in a new issue