Skip to content

Commit

Permalink
chore:select add label
Browse files Browse the repository at this point in the history
  • Loading branch information
lerte committed Oct 31, 2024
1 parent 16b26bc commit c8c3b7b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 361 deletions.
4 changes: 2 additions & 2 deletions apps/docs/src/usages/select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ export default () => {

return (
<div className="max-sm:flex-wrap flex gap-4">
<Select items={options}>
<Select label="Select Project" items={options}>
{(item) => <SelectOption>{item.name}</SelectOption>}
</Select>
<Select variant="outlined" items={options}>
<Select label="Select Project" variant="outlined" items={options}>
{(item) => <SelectOption>{item.name}</SelectOption>}
</Select>
</div>
Expand Down
22 changes: 5 additions & 17 deletions packages/actify/src/components/Select/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,9 @@ const Select = <T extends object>(props: SelectProps<T>) => {
const state = useSelectState(props)
const ref = React.useRef(null)

const { labelProps, triggerProps, valueProps, menuProps } = useSelect(
props,
state,
ref
)
const { triggerProps, valueProps, menuProps } = useSelect(props, state, ref)

const { variant = 'filled' } = props
const label = state.selectedItem
? state.selectedItem.rendered
: 'Select an option'

let Tag = FilledField
if (variant == 'filled') {
Expand All @@ -44,10 +37,9 @@ const Select = <T extends object>(props: SelectProps<T>) => {

return (
<div
style={{ display: 'inline-flex', ...props.style }}
className={clsx(styles['outlined-select'], props.className)}
style={props.style}
className={clsx(styles['select'], props.className)}
>
{props.label && <Label {...labelProps}>{props.label}</Label>}
<HiddenSelect
state={state}
triggerRef={ref}
Expand All @@ -57,12 +49,8 @@ const Select = <T extends object>(props: SelectProps<T>) => {
/>

<Tag ref={ref} {...triggerProps}>
<Label
aria-label={label?.toString()}
{...valueProps}
style={{ lineHeight: '24px' }}
>
{label}
<Label {...valueProps} style={{ lineHeight: '24px' }}>
{state.selectedItem ? state.selectedItem.rendered : props.label}
</Label>
<TrailingIcon isOpen={state.isOpen} />
</Tag>
Expand Down
Loading

0 comments on commit c8c3b7b

Please sign in to comment.