Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add items prop, proper height and validation lib support to select #480

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

CryptAlchemy
Copy link
Contributor

Items are passed into the Select as either an object or an array via the items prop. Breaks existing Select implementations as there is no backwards-compatibility for in the Select; an array or object must be used. This deprecates Option.svelte.

The Select scales the menu according to device height if menu$fixed={true} prop is passed.

Select respects hiddenInput prop by appropriately calling events on the field, including the SMUISelect:change event. The hiddenInput also contains a data-smui="true" prop for easy identification in standard browser-level form validation libraries.

Closes #242, #468

Copy link
Owner

@hperrin hperrin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some issues that would need to be addressed before this approach would be acceptable. I also don't understand the need to use an items prop instead of a slot.

Comment on lines +54 to +57
bind:this={input}
data-smui="true"
type="text"
style="width: 100%;height: 100%;position: absolute;opacity: 0;"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will cause this input to be announced to screen readers.

Comment on lines +64 to +69
<style>
input[data-smui="true"]:focus-visible {
outline: none;
caret-color: transparent;
}
</style>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will not work without "unsafe-inline" in the CSP.

@@ -174,6 +184,7 @@
</div>

<Menu
style="min-width: {clientWidth ?? 0}px;"
Copy link
Owner

@hperrin hperrin Jul 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be overwritten by the "list$style" prop. You would need to define, initialize, and incorporate that prop into here.

Comment on lines +211 to +219
{#if items}
{#each items as item}
{#if item.name && item.value}
<Option value={item.value}>{item.name}</Option>
{:else}
<Option value={item}>{item}</Option>
{/if}
{/each}
{/if}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reason for this instead of a slot?

@@ -250,6 +272,7 @@
import NotchedOutline from '@smui/notched-outline';

import HelperText from './helper-text/HelperText.svelte';
import Item from '@smui/list/src/Item.svelte';
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not how you import from other components. It would be:

import { Item } from '@smui/list';

@@ -258,6 +281,8 @@
return value === uninitializedValue;
}

export let input: any;
Copy link
Owner

@hperrin hperrin Jul 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be more strict. "any" is not appropriate. Use HTMLInputElement.

@@ -294,6 +319,9 @@
export let dropdownIcon$use: ActionArray = [];
export let dropdownIcon$class = '';
export let menu$class = '';
export let items: any[] = [];

let clientWidth;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs a type.

Comment on lines +336 to +340
var didInputInitial = false;
$: if(input && !didInputInitial) {
didInputInitial = true;
value = input.value;
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will force value to be a string no matter what type it is.

https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement#value


// If items array changes, reset value
let items_previous: any[] = [];
$: if (JSON.stringify(items) !== JSON.stringify(items_previous)) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This causes potentially expensive JSON.stringify computations to run unnecessarily. It also means any change in items that has the same JSON representation wouldn't be picked up.

@hperrin
Copy link
Owner

hperrin commented Apr 3, 2023

Using an items array limits the structure of whatever you pass into it, so I wouldn't be willing to do that. If you can make it just the height changes, I might could accept that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Select in v4.1.0 is missing dynamic max-height
2 participants