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(dropdown): add show/hide events #301

Merged
merged 2 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions docs/components/dropdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -257,3 +257,26 @@ import { FwbDropdown, FwbListGroup, FwbListGroupItem } from 'flowbite-vue'
import { FwbDropdown, ListGroup, ListGroupItem } from 'flowbite-vue'
</script>
```

## API

### Props
| Name | Values | Default |
|----------|--------|---------|
| placement | `DropdownPlacement` | `'bottom'` |
| text | `string` | `''` |
| transition | `string` | `''` |
| closeInside | `boolean` | `false` |
| alignToEnd | `boolean` | `false` |

### Events
| Name | Description |
|------|------------------------|
| show | the dropdown is opened |
| hide | the dropdown is closed |

### Slots
| Name | Description |
|------------|-------------------|
| default | dropdown content |
| suffix | button suffix |
18 changes: 17 additions & 1 deletion src/components/FwbDropdown/FwbDropdown.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
</template>

<script lang="ts" setup>
import { computed, ref, toRef } from 'vue'
import { computed, ref, toRef, watch } from 'vue'
import { onClickOutside } from '@vueuse/core'
import type { DropdownPlacement } from './types'
import FwbButton from '@/components/FwbButton/FwbButton.vue'
Expand Down Expand Up @@ -74,6 +74,22 @@ const props = withDefaults(
},
)

const emit = defineEmits<{
'show': []
'hide': []
}>()

watch(
visible,
(isVisible: boolean) => {
if (isVisible) {
emit('show')
} else {
emit('hide')
}
},
)
Comment on lines +82 to +91
Copy link

@coderabbitai coderabbitai bot Jul 30, 2024

Choose a reason for hiding this comment

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

LGTM! Ensure proper test coverage.

The watch function is well-implemented and enhances the component's interactivity by emitting show and hide events based on the visible state. Ensure that this new functionality is covered by tests.

Do you want me to generate the unit testing code or open a GitHub issue to track this task?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i believe it's out of the scope of the PR to set up a bunch of new tests. but a task for testing in general is up to the maintainers, not me

Copy link

Choose a reason for hiding this comment

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

@Flambe, understood. I'll go ahead and open a GitHub issue to track the task of adding tests for the show and hide events. This will ensure that the new functionality is properly covered in the future.

Would you like me to proceed with creating the issue?


Learnings added
Learnt from: Flambe
PR: themesberg/flowbite-vue#301
File: src/components/FwbDropdown/FwbDropdown.vue:82-91
Timestamp: 2024-07-30T09:40:49.346Z
Learning: When a user indicates that setting up new tests is out of the scope of a PR, offer to open a GitHub issue to track the task of adding the necessary tests.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.


const placementTransitionMap: Record<DropdownPlacement, string> = {
bottom: 'to-bottom',
left: 'to-left',
Expand Down
Loading