Skip to content

Commit

Permalink
feat(InputMenu/Select/SelectMenu): arrow prop implementation (#2503)
Browse files Browse the repository at this point in the history
Co-authored-by: Benjamin Canac <[email protected]>
  • Loading branch information
hywax and benjamincanac authored Oct 31, 2024
1 parent c85ba43 commit f26f6c8
Show file tree
Hide file tree
Showing 12 changed files with 321 additions and 10 deletions.
25 changes: 25 additions & 0 deletions docs/content/3.components/input-menu.md
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,31 @@ props:
---
::

### Arrow

Use the `arrow` prop to display an arrow on the InputMenu.

::component-code
---
prettier: true
ignore:
- items
- modelValue
- arrow
external:
- items
- modelValue
props:
modelValue: Backlog
arrow: true
items:
- Backlog
- Todo
- In Progress
- Done
---
::

### Color

Use the `color` prop to change the ring color when the InputMenu is focused.
Expand Down
27 changes: 27 additions & 0 deletions docs/content/3.components/select-menu.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,33 @@ props:
---
::

### Arrow

Use the `arrow` prop to display an arrow on the SelectMenu.

::component-code
---
prettier: true
ignore:
- items
- modelValue
- class
- arrow
external:
- items
- modelValue
props:
modelValue: Backlog
arrow: true
items:
- Backlog
- Todo
- In Progress
- Done
class: 'w-48'
---
::

### Color

Use the `color` prop to change the ring color when the SelectMenu is focused.
Expand Down
32 changes: 31 additions & 1 deletion docs/content/3.components/select.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ props:

### Content

Use the `content` prop to control how the Select content is rendered, like its its `align`, `side` or `position` for example. Defaults to `popper` to match other components.
Use the `content` prop to control how the Select content is rendered, like its `align`, `side` or `position` for example.

::warning
The `content.align`, `content.side`, etc. properties only apply when `content.position` is set to `popper`.
Expand Down Expand Up @@ -209,6 +209,36 @@ props:
Read more about the `content.position` prop in the [Radix Vue documentation](https://www.radix-vue.com/components/select.html#change-the-positioning-mode).
::

<!--
### Arrow
Use the `arrow` prop to display an arrow on the Select.
::component-code
---
prettier: true
ignore:
- items
- modelValue
- class
- arrow
external:
- items
- modelValue
props:
modelValue: 'Todo'
arrow: true
items:
- Backlog
- Todo
- In Progress
- Done
class: 'w-48'
---
::
-->

### Color

Use the `color` prop to change the ring color when the Select is focused.
Expand Down
6 changes: 5 additions & 1 deletion src/runtime/components/InputMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export interface InputMenuSlots<T> {

<script setup lang="ts" generic="T extends MaybeArrayOfArrayItem<I>, I extends MaybeArrayOfArray<InputMenuItem | AcceptableValue> = MaybeArrayOfArray<InputMenuItem | AcceptableValue>, V extends SelectItemKey<T> | undefined = undefined, M extends boolean = false">
import { computed, ref, toRef, onMounted } from 'vue'
import { ComboboxRoot, ComboboxAnchor, ComboboxInput, ComboboxTrigger, ComboboxPortal, ComboboxContent, ComboboxViewport, ComboboxEmpty, ComboboxGroup, ComboboxLabel, ComboboxSeparator, ComboboxItem, ComboboxItemIndicator, TagsInputRoot, TagsInputItem, TagsInputItemText, TagsInputItemDelete, TagsInputInput, useForwardPropsEmits } from 'radix-vue'
import { ComboboxRoot, ComboboxArrow, ComboboxAnchor, ComboboxInput, ComboboxTrigger, ComboboxPortal, ComboboxContent, ComboboxViewport, ComboboxEmpty, ComboboxGroup, ComboboxLabel, ComboboxSeparator, ComboboxItem, ComboboxItemIndicator, TagsInputRoot, TagsInputItem, TagsInputItemText, TagsInputItemDelete, TagsInputInput, useForwardPropsEmits } from 'radix-vue'
import { defu } from 'defu'
import * as isEqual from 'fast-deep-equal'
import { reactivePick } from '@vueuse/core'
Expand Down Expand Up @@ -156,6 +156,8 @@ const searchTerm = defineModel<string>('searchTerm', { default: '' })
const appConfig = useAppConfig()
const rootProps = useForwardPropsEmits(reactivePick(props, 'as', 'modelValue', 'defaultValue', 'selectedValue', 'open', 'defaultOpen', 'multiple', 'resetSearchTermOnBlur'), emits)
const contentProps = toRef(() => defu(props.content, { side: 'bottom', sideOffset: 8, position: 'popper' }) as ComboboxContentProps)
const arrowProps = toRef(() => props.arrow as ComboboxArrowProps)
const { emitFormBlur, emitFormChange, emitFormInput, size: formGroupSize, color, id, name, highlight, disabled } = useFormField<InputProps>(props)
const { orientation, size: buttonGroupSize } = useButtonGroup<InputProps>(props)
const { isLeading, isTrailing, leadingIconName, trailingIconName } = useComponentIcons(toRef(() => defu(props, { trailingIcon: appConfig.ui.icons.chevronDown })))
Expand Down Expand Up @@ -387,6 +389,8 @@ defineExpose({
</template>
</ComboboxGroup>
</ComboboxViewport>

<ComboboxArrow v-if="!!arrow" v-bind="arrowProps" :class="ui.arrow({ class: props.ui?.arrow })" />
</ComboboxContent>
</ComboboxPortal>
</ComboboxRoot>
Expand Down
5 changes: 4 additions & 1 deletion src/runtime/components/Select.vue
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export interface SelectSlots<T> {

<script setup lang="ts" generic="T extends MaybeArrayOfArrayItem<I>, I extends MaybeArrayOfArray<SelectItem | AcceptableValue> = MaybeArrayOfArray<SelectItem | AcceptableValue>, V extends SelectItemKey<T> | undefined = undefined">
import { computed, toRef } from 'vue'
import { SelectRoot, SelectTrigger, SelectValue, SelectPortal, SelectContent, SelectViewport, SelectLabel, SelectGroup, SelectItem, SelectItemIndicator, SelectItemText, SelectSeparator, useForwardPropsEmits } from 'radix-vue'
import { SelectRoot, SelectArrow, SelectTrigger, SelectValue, SelectPortal, SelectContent, SelectViewport, SelectLabel, SelectGroup, SelectItem, SelectItemIndicator, SelectItemText, SelectSeparator, useForwardPropsEmits } from 'radix-vue'
import { defu } from 'defu'
import { reactivePick } from '@vueuse/core'
import { useAppConfig } from '#imports'
Expand All @@ -122,6 +122,7 @@ const slots = defineSlots<SelectSlots<T>>()
const appConfig = useAppConfig()
const rootProps = useForwardPropsEmits(reactivePick(props, 'modelValue', 'defaultValue', 'open', 'defaultOpen', 'disabled', 'autocomplete', 'required'), emits)
const contentProps = toRef(() => defu(props.content, { side: 'bottom', sideOffset: 8, position: 'popper' }) as SelectContentProps)
const arrowProps = toRef(() => props.arrow as SelectArrowProps)
const { emitFormChange, emitFormInput, emitFormBlur, size: formGroupSize, color, id, name, highlight, disabled } = useFormField<InputProps>(props)
const { orientation, size: buttonGroupSize } = useButtonGroup<InputProps>(props)
Expand Down Expand Up @@ -241,6 +242,8 @@ function onUpdateOpen(value: boolean) {
</template>
</SelectGroup>
</SelectViewport>

<SelectArrow v-if="!!arrow" v-bind="arrowProps" :class="ui.arrow({ class: props.ui?.arrow })" />
</SelectContent>
</SelectPortal>
</SelectRoot>
Expand Down
6 changes: 5 additions & 1 deletion src/runtime/components/SelectMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export interface SelectMenuSlots<T> {

<script setup lang="ts" generic="T extends MaybeArrayOfArrayItem<I>, I extends MaybeArrayOfArray<SelectMenuItem | AcceptableValue> = MaybeArrayOfArray<SelectMenuItem | AcceptableValue>, V extends SelectItemKey<T> | undefined = undefined, M extends boolean = false">
import { computed, toRef } from 'vue'
import { ComboboxRoot, ComboboxAnchor, ComboboxInput, ComboboxTrigger, ComboboxPortal, ComboboxContent, ComboboxViewport, ComboboxEmpty, ComboboxGroup, ComboboxLabel, ComboboxSeparator, ComboboxItem, ComboboxItemIndicator, useForwardPropsEmits } from 'radix-vue'
import { ComboboxRoot, ComboboxArrow, ComboboxAnchor, ComboboxInput, ComboboxTrigger, ComboboxPortal, ComboboxContent, ComboboxViewport, ComboboxEmpty, ComboboxGroup, ComboboxLabel, ComboboxSeparator, ComboboxItem, ComboboxItemIndicator, useForwardPropsEmits } from 'radix-vue'
import { defu } from 'defu'
import * as isEqual from 'fast-deep-equal'
import { reactivePick } from '@vueuse/core'
Expand Down Expand Up @@ -146,6 +146,8 @@ const searchTerm = defineModel<string>('searchTerm', { default: '' })
const appConfig = useAppConfig()
const rootProps = useForwardPropsEmits(reactivePick(props, 'modelValue', 'defaultValue', 'selectedValue', 'open', 'defaultOpen', 'multiple', 'resetSearchTermOnBlur'), emits)
const contentProps = toRef(() => defu(props.content, { side: 'bottom', sideOffset: 8, position: 'popper' }) as ComboboxContentProps)
const arrowProps = toRef(() => props.arrow as ComboboxArrowProps)
const { emitFormBlur, emitFormInput, emitFormChange, size: formGroupSize, color, id, name, highlight, disabled } = useFormField<InputProps>(props)
const { orientation, size: buttonGroupSize } = useButtonGroup<InputProps>(props)
const { isLeading, isTrailing, leadingIconName, trailingIconName } = useComponentIcons(toRef(() => defu(props, { trailingIcon: appConfig.ui.icons.chevronDown })))
Expand Down Expand Up @@ -324,6 +326,8 @@ function onUpdateOpen(value: boolean) {
</template>
</ComboboxGroup>
</ComboboxViewport>

<ComboboxArrow v-if="!!arrow" v-bind="arrowProps" :class="ui.arrow({ class: props.ui?.arrow })" />
</ComboboxContent>
</ComboboxPortal>
</ComboboxRoot>
Expand Down
Loading

0 comments on commit f26f6c8

Please sign in to comment.