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

Enhancement: Set OcModal Buttons to equal width #9671

Merged
merged 8 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
6 changes: 6 additions & 0 deletions changelog/unreleased/enhancement-modal-buttons-same-width
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Enhancement: OcModal set buttons to same width

We've adjusted the button widths for every modal so the options look more equal.

https://github.com/owncloud/web/pull/9671
https://github.com/owncloud/web/issues/9641
40 changes: 39 additions & 1 deletion packages/design-system/src/components/OcModal/OcModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,15 @@
<div class="oc-modal-body-actions oc-flex oc-flex-right">
<oc-button
class="oc-modal-body-actions-cancel"
ref="cancelButton"
:variation="buttonCancelVariation"
:appearance="buttonCancelAppearance"
@click="cancelModalAction"
v-text="buttonCancelText"
/>
<oc-button
v-if="buttonSecondaryText"
ref="secondaryButton"
class="oc-modal-body-actions-secondary oc-ml-s"
:variation="buttonSecondaryVariation"
:appearance="buttonSecondaryAppearance"
Expand All @@ -82,6 +84,7 @@
/>
<oc-button
v-if="!withoutButtonConfirm"
ref="primaryButton"
class="oc-modal-body-actions-confirm oc-ml-s"
variation="primary"
:appearance="buttonConfirmAppearance"
Expand All @@ -96,7 +99,7 @@
</template>

<script lang="ts">
import { defineComponent, PropType, ComponentPublicInstance } from 'vue'
import { defineComponent, PropType, ComponentPublicInstance, ref, onMounted, unref } from 'vue'
import OcButton from '../OcButton/OcButton.vue'
import OcCheckbox from '../OcCheckbox/OcCheckbox.vue'
import OcIcon from '../OcIcon/OcIcon.vue'
Expand Down Expand Up @@ -393,6 +396,41 @@ export default defineComponent({
checkboxValue: false
}
},
setup() {
const primaryButton = ref(null)
const secondaryButton = ref(null)
const cancelButton = ref(null)

const setButtonsEqualWidth = () => {
const _primaryButton = unref(primaryButton)
const _secondaryButton = unref(secondaryButton)
const _cancelButton = unref(cancelButton)

const primaryWidth = _primaryButton?.$el?.offsetWidth || 0
const secondaryWidth = _secondaryButton?.$el?.offsetWidth || 0
const cancelWidth = _cancelButton?.$el?.offsetWidth || 0
const maxWidth = Math.max(primaryWidth, secondaryWidth, cancelWidth)

if (_primaryButton && _primaryButton.$el) {
lookacat marked this conversation as resolved.
Show resolved Hide resolved
_primaryButton.$el.style.minWidth = `${maxWidth}px`
}
if (_secondaryButton && _secondaryButton.$el) {
_secondaryButton.$el.style.minWidth = `${maxWidth}px`
}
if (_cancelButton && _cancelButton.$el) {
_cancelButton.$el.style.minWidth = `${maxWidth}px`
}
}
onMounted(() => {
setButtonsEqualWidth()
})

return {
primaryButton,
secondaryButton,
cancelButton
}
},
computed: {
initialFocusRef(): FocusTargetOrFalse {
if (this.focusTrapInitial) {
Expand Down