Skip to content

Commit

Permalink
Fix default multiselect height
Browse files Browse the repository at this point in the history
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
  • Loading branch information
skjnldsv committed Nov 26, 2020
1 parent 15fde7c commit e4b04db
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 24 deletions.
14 changes: 13 additions & 1 deletion src/components/ListItemIcon/ListItemIcon.vue
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,15 @@ export default {
default: defaultSize,
},
/**
* Disable the margins of this component.
* Useful for integration in Multiselect for example
*/
noMargin: {
type: Boolean,
default: false,
},
/**
* See the [Avatar](#Avatar) displayName prop
* Fallback to title
Expand Down Expand Up @@ -189,8 +198,11 @@ export default {
},
cssVars() {
// Don't use margin to calculate the height if noMargin
const margin = this.noMargin ? 0 : this.margin
return {
'--height': this.avatarSize + 2 * this.margin + 'px',
'--height': this.avatarSize + 2 * margin + 'px',
'--margin': this.margin + 'px',
}
},
Expand Down
42 changes: 22 additions & 20 deletions src/components/Multiselect/Multiselect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ export default {

### User layout
By specifying `:user-select="true"`, you can benefit from a fully formatted layout.
The singleLabel slot here is optional of course and here for demonstration purposes

> **Note:** Any extra binding from the object will be added as attribute (`$attrs`) on the ListItemIcon component used here

Expand All @@ -110,33 +111,34 @@ By specifying `:user-select="true"`, you can benefit from a fully formatted layo
<Multiselect v-model="value" :options="formatedOptions"
label="displayName" track-by="user"
:user-select="true"
style="width: 250px" />
style="width: 250px">
<template #singleLabel="{ option }">
<ListItemIcon v-bind="option" :title="option.displayName" :avatar-size="24" :no-margin="true" />
</template>
</Multiselect>
</template>

<script>
import Multiselect from '../index'
// Building fake data for the docs
const options = ['admin', 'user1', 'user2', 'guest', 'group1']
const formattedOptions = options.map(item => {
return {
user: item,
displayName: item,
subtitle: `This is the ${item.startsWith('group') ? 'group' : 'user'} ${item}`,
icon: item.startsWith('group') ? 'icon-group' : 'icon-user',
isNoUser: item.startsWith('group')
}
})
export default {
data() {
return {
value: null,
options: ['admin', 'user1', 'user2', 'guest', 'group1']
}
return {
value: formattedOptions[0],
formattedOptions,
}
},
computed: {
// Building fake data for the docs
formatedOptions() {
return this.options.map(item => {
return {
user: item,
displayName: item,
subtitle: `This is the ${item.startsWith('group') ? 'group' : 'user'} ${item}`,
icon: item.startsWith('group') ? 'icon-group' : 'icon-user',
isNoUser: item.startsWith('group')
}
})
}
}
}
</script>
```
Expand Down
15 changes: 12 additions & 3 deletions src/components/Multiselect/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

/* Force single multiselect value to be shown when not active */
&:not(.multiselect--active) .multiselect__single {
position: absolute;
width: 100%;
z-index: 2 !important;
}

// active state, force the input to be shown, we don't want
Expand Down Expand Up @@ -64,6 +64,8 @@
position: relative;
border-radius: 3px;
min-height: 34px;
height: 100%;

/* tag wrapper */
.multiselect__tags-wrap {
align-items: center;
Expand Down Expand Up @@ -127,9 +129,16 @@
flex: 0 0 100%;
z-index: 1; /* above input */
background-color: var(--color-main-background);
cursor: pointer;
line-height: 18px; // 32px - 2*6px (padding) - 2*1px (border)
color: var(--color-text-lighter); // like the input
// Align content and make the flow smoother
display: flex;
align-items: center;

// Anything inside will trigger the select opening
&, * {
cursor: pointer;
}
}
/* displayed text if tag limit reached */
.multiselect__strong,
Expand All @@ -153,7 +162,7 @@
margin: 0;
opacity: 0;
/* let's leave it on top of tags but hide it */
height: 100%;
height: 100% !important;
border: none;
/* override hide to force show the placeholder */
display: block !important;
Expand Down

0 comments on commit e4b04db

Please sign in to comment.