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

fix(NcModal): Close button should be visible even if modal content is scrolled #4350

Merged
merged 1 commit into from Aug 3, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 28 additions & 0 deletions cypress/component/modal.cy.ts
@@ -0,0 +1,28 @@
import { mount } from 'cypress/vue2'
import NcModal from '../../src/components/NcModal/NcModal.vue'
import type { Component } from 'vue'

describe('NcModal', () => {
it('close button is visible when content is scrolled', () => {
mount(NcModal, {
propsData: {
show: true,
size: 'small',
name: 'Name',
},
slots: {
// Create two div as children, first is 100vh = overflows the content, second just gets some data attribute so we can scroll into view
default: {
render: (h) =>
h('div', [
h('div', { style: 'height: 100vh;' }),
h('div', { attrs: { 'data-cy': 'bottom' } }),
]),
} as Component,
},
})

cy.get('[data-cy="bottom"]').scrollIntoView()
cy.get('button.modal-container__close').should('be.visible')
})
})
15 changes: 11 additions & 4 deletions src/components/NcModal/NcModal.vue
Expand Up @@ -271,8 +271,6 @@ export default {

<!-- Content -->
<div :id="'modal-description-' + randId" class="modal-container">
<!-- @slot Modal content to render -->
<slot />
<!-- Close modal -->
<NcButton v-if="canClose && closeButtonContained"
type="tertiary"
Expand All @@ -283,6 +281,10 @@ export default {
<Close :size="20" />
</template>
</NcButton>
<div class="modal-container__content">
<!-- @slot Modal content to render -->
<slot />
</div>
</div>

<!-- Navigation button -->
Expand Down Expand Up @@ -913,19 +915,24 @@ export default {
/* Content */
.modal-container {
position: relative;
display: block;
overflow: auto; // avoids unecessary hacks if the content should be bigger than the modal
display: flex;
padding: 0;
transition: transform 300ms ease;
border-radius: var(--border-radius-large);
background-color: var(--color-main-background);
color: var(--color-main-text);
box-shadow: 0 0 40px rgba(0, 0, 0, .2);

&__close {
position: absolute;
top: 4px;
right: 4px;
}

&__content {
width: 100%;
overflow: auto; // avoids unecessary hacks if the content should be bigger than the modal
}
}

// Sizing
Expand Down