Skip to content

Commit

Permalink
Add id to searchable select (viamrobotics#524)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrloureed authored Jun 3, 2024
1 parent c6b4af0 commit b5621ea
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@viamrobotics/prime-core",
"version": "0.0.121",
"version": "0.0.122",
"publishConfig": {
"access": "public"
},
Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/lib/select/searchable-select.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ export let values: string[] = [];
/** The placeholder of the input. */
export let placeholder = '';
/** Optional id used in parent label `for` attribute */
export let id: string | undefined = undefined;
/**
* Whether value must be constrained to `options` on change.
* - `false` (Default) - any value may be selected
Expand Down Expand Up @@ -307,6 +310,7 @@ const handleKeydown = createHandleKey({
menuId={LIST_ID}
isOpen={isExpanded}
isFocused={menuState === FOCUS_ITEM ? false : undefined}
{id}
cx={[{ 'caret-transparent': menuState === FOCUS_ITEM }, inputCx]}
icon={selectedSearchOption?.icon}
aria-autocomplete="list"
Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/lib/select/select-input.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ export let state: InputState = InputStates.NONE;
export let inputElement: HTMLInputElement | undefined = undefined;
export let icon: IconName | undefined = undefined;
/** Optional id used in parent label `for` attribute */
export let id: string | undefined = undefined;
/** Additional CSS classes to pass to the input. */
let extraClasses: cx.Argument = '';
export { extraClasses as cx };
Expand Down Expand Up @@ -61,6 +64,7 @@ $: errorClasses =
<input
bind:value
bind:this={inputElement}
{id}
role="combobox"
readonly={disabled ? true : undefined}
aria-controls={menuId}
Expand Down
26 changes: 19 additions & 7 deletions packages/core/src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -1065,18 +1065,30 @@ const onHoverDelayMsInput = (event: Event) => {
/>
</Label>

<div>
<div class="flex flex-col gap-1">
<Label
for="targetID"
cx="whitespace-nowrap"
>
For attribute example
For attribute example with SearchableSelect
</Label>
<Input
cx="max-w-[70px]"
id="targetID"
name="name"
/>
<div class="max-w-fit">
<SearchableSelect
id="targetID"
exclusive
options={[
{ value: 'First Option', description: 'First option' },
'Option 2',
{ value: 'C.) Option', description: 'second' },
'A really long forth option just in case you need it',
]}
placeholder="Select an option"
onChange={(value) => {
// eslint-disable-next-line no-console
console.log('Selected', value);
}}
/>
</div>
</div>
</div>

Expand Down

0 comments on commit b5621ea

Please sign in to comment.