Skip to content

Commit

Permalink
feat(VNavigationDrawer): add rail prop v-model support (#16352)
Browse files Browse the repository at this point in the history
resolves #16022
  • Loading branch information
johnleider committed Jan 3, 2023
1 parent a11e937 commit 22f591b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ export const VNavigationDrawer = defineComponent({
default: null,
},
permanent: Boolean,
rail: Boolean,
rail: {
type: Boolean as PropType<boolean | null>,
default: null,
},
railWidth: {
type: [Number, String],
default: 56,
Expand Down Expand Up @@ -74,9 +77,10 @@ export const VNavigationDrawer = defineComponent({

emits: {
'update:modelValue': (val: boolean) => true,
'update:rail': (val: boolean) => true,
},

setup (props, { attrs, slots }) {
setup (props, { attrs, emit, slots }) {
const { isRtl } = useRtl()
const { themeClasses } = provideTheme(props)
const { borderClasses } = useBorder(props)
Expand Down Expand Up @@ -106,6 +110,10 @@ export const VNavigationDrawer = defineComponent({
location.value !== 'bottom'
)

if (props.expandOnHover && props.rail != null) {
watch(isHovering, val => emit('update:rail', !val))
}

if (!props.disableResizeWatcher) {
watch(isTemporary, val => !props.permanent && (nextTick(() => isActive.value = !val)))
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/// <reference types="../../../../types/cypress" />

import { VLayout } from '@/components/VLayout'
import { VMain } from '@/components/VMain'
import { VNavigationDrawer } from '..'
import { ref } from 'vue'

describe('VNavigationDrawer', () => {
beforeEach(() => {
Expand Down Expand Up @@ -48,6 +50,31 @@ describe('VNavigationDrawer', () => {
cy.get('.v-navigation-drawer').should('have.css', 'width', '56px')
})

it('should change width when using bound and unbound rail and expandOnHover', () => {
const rail = ref(true)

cy.mount(() => (
<VLayout>
<VNavigationDrawer expand-on-hover v-model:rail={ rail.value } />

<VMain />
</VLayout>
))

cy.get('.v-navigation-drawer').should('have.css', 'width', '56px')
cy.get('.v-main').should('have.css', 'padding-left', '56px')

cy.get('.v-navigation-drawer').trigger('mouseenter')

cy.get('.v-navigation-drawer').should('have.css', 'width', '256px')
cy.get('.v-main').should('have.css', 'padding-left', '256px')

cy.get('.v-navigation-drawer').trigger('mouseleave')

cy.get('.v-navigation-drawer').should('have.css', 'width', '56px')
cy.get('.v-main').should('have.css', 'padding-left', '56px')
})

it('should hide drawer if window resizes below mobile breakpoint', () => {
cy.mount(() => (
<VLayout>
Expand Down

0 comments on commit 22f591b

Please sign in to comment.