Skip to content

Commit de6cb20

Browse files
Fixing some issues with mobile
1 parent 6cfbbe0 commit de6cb20

File tree

7 files changed

+30
-24
lines changed

7 files changed

+30
-24
lines changed

src/plugin/VResizeDrawer.vue

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ const drawerStyles = computed(() => useDrawerStyles({
220220
rail: settings.value.rail,
221221
railWidth: settings.value.railWidth,
222222
resizedAmount: resizedAmount.value,
223-
widthSnapBack: settings.value.widthSnapBack,
223+
snapBack: settings.value.snapBack || settings.value.widthSnapBack,
224224
}));
225225
226226
const drawerWidth = computed<string | number | undefined>(() => {
@@ -279,7 +279,6 @@ const isAllowedHandlePosition = computed<boolean>(() => {
279279
});
280280
281281
282-
283282
// -------------------------------------------------- Handle Icon //
284283
const handleIconStyles = computed(() => useHandleIconStyles({
285284
color: props.handleColor,
@@ -352,7 +351,7 @@ function drawerResizeEvent(e: MouseEvent | TouchEvent, amount: number): void {
352351
}
353352
354353
if (settings.value.location === 'bottom') {
355-
amountValue = document.body.scrollHeight - amountValue + (iconSizeUnit.value / 2);
354+
amountValue = window.innerHeight - amountValue + (iconSizeUnit.value / 2);
356355
}
357356
358357
resizedAmount.value = useConvertToUnit({ value: amountValue }) || undefined;
@@ -488,7 +487,6 @@ function handleStart(e: MouseEvent | TouchEvent, eventOffsetX: number): void {
488487
offsetX = settings.value.handleBorderWidth as number || 1;
489488
}
490489
491-
492490
handleEvents.mouseUp = false;
493491
494492
if (eventOffsetX < offsetX) {
@@ -517,11 +515,14 @@ function handleStart(e: MouseEvent | TouchEvent, eventOffsetX: number): void {
517515
518516
function handleMouseDown(e: MouseEvent): void {
519517
const offset = isTopOrBottom.value ? e.offsetY : e.offsetX;
518+
520519
handleStart(e, offset);
521520
}
522521
523522
function handleTouchstart(e: TouchEvent): void {
524-
const client = (isTopOrBottom.value ? e.touches[0]?.radiusY : e.touches[0]?.radiusX) ?? 0;
523+
let client = (isTopOrBottom.value ? e.touches[0]?.radiusY : e.touches[0]?.radiusX) ?? 0;
524+
client = client / 2;
525+
525526
handleStart(e, client);
526527
}
527528

src/plugin/composables/__tests__/styles.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ describe('Styles Composable', () => {
142142
expect(data).toMatchInlineSnapshot(`
143143
{
144144
"backgroundColor": "transparent",
145-
"height": "100%",
145+
"height": "undefinedpx",
146146
"transform": undefined,
147147
"width": "undefinedpx",
148148
}

src/plugin/composables/helpers.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ export const useConvertToNumber = (val: string | number): number => {
7979
export const useUnitToPx = (valueWithUnit: Props['handleIconSize']): number => {
8080
if (!valueWithUnit) return 0;
8181

82+
83+
// check if string valueWithUnit contains px
84+
if (typeof valueWithUnit === 'number') {
85+
return valueWithUnit;
86+
}
87+
8288
// Create a temporary element for calculating the value
8389
const tempElement = document.createElement('div');
8490
tempElement.style.position = 'absolute';

src/plugin/composables/styles.ts

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ export const iconSizes = {
1818

1919
// -------------------------------------------------- Drawer //
2020
export const useDrawerStyles: UseDrawerStyles = (options) => {
21-
const { isMouseDown, location, maxWidth, minWidth, rail, railWidth, resizedAmount, widthSnapBack } = options;
21+
const { isMouseDown, location, maxWidth, minWidth, rail, railWidth, resizedAmount, snapBack } = options;
2222

2323
if (rail) {
2424
return {};
2525
}
2626

2727
let mountValue = rail ? railWidth : unref(resizedAmount);
2828

29-
if (!widthSnapBack) {
29+
if (!snapBack) {
3030
if (parseInt(mountValue as string) >= parseInt(maxWidth as string)) {
3131
mountValue = parseInt(maxWidth as string);
3232
}
@@ -40,6 +40,7 @@ export const useDrawerStyles: UseDrawerStyles = (options) => {
4040

4141
if (location === 'top' || location === 'bottom') {
4242
response = {
43+
maxHeight: `${useConvertToUnit({ value: mountValue as string }) as string} !important`,
4344
minHeight: `${useConvertToUnit({ value: mountValue as string }) as string} !important`,
4445
transitionDuration: unref(isMouseDown) ? '0s' : '.2s',
4546
width: '100%',
@@ -61,22 +62,18 @@ export const useHandleContainerStyles: UseHandleContainerStyles = (options) => {
6162
const { borderWidth, handleColor, iconSizeUnit, location, position, theme } = options;
6263

6364
const transform = `translateX(-50%) ${location === 'top' ? 'rotate(90deg)' : 'rotate(-90deg)'}`;
64-
let height = '100%';
65-
let width = '100%';
65+
let height = `${iconSizeUnit}px`;
66+
let width = `${iconSizeUnit}px`;
6667

67-
if (location === 'bottom' || location === 'top') {
68-
height = `${iconSizeUnit}px`;
69-
70-
if (position === 'border') {
68+
if (position === 'border') {
69+
if (location === 'bottom' || location === 'top') {
7170
height = useConvertToUnit({ value: borderWidth as string }) as string;
7271
}
73-
}
74-
else {
75-
width = useConvertToUnit({ value: borderWidth as string }) as string;
76-
}
77-
72+
else {
73+
height = '100%';
74+
width = useConvertToUnit({ value: borderWidth as string }) as string;
75+
}
7876

79-
if (position === 'border') {
8077
return {
8178
backgroundColor: useGetColor(handleColor as string, theme),
8279
height,
@@ -88,7 +85,7 @@ export const useHandleContainerStyles: UseHandleContainerStyles = (options) => {
8885
backgroundColor: 'transparent',
8986
height: height,
9087
transform: location === 'top' || location === 'bottom' ? transform : undefined,
91-
width: `${iconSizeUnit}px`,
88+
width,
9289
};
9390
};
9491

src/plugin/styles/main.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@
9999
}
100100

101101
&--top {
102+
top: 0 !important;
102103
transition: min-height 0.3s;
103104

104105
.v-resize-drawer--handle-container {

src/plugin/types/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export type Classes = {
2121
export type EmitEventNames = 'handle:click' | 'handle:dblclick' | 'handle:drag' | 'handle:mousedown' | 'handle:mouseup' | 'handle:touchend' | 'handle:touchmove' | 'handle:touchstart';
2222
export type StorageType = 'local' | 'session';
2323
export type HandlePositions = 'bottom' | 'border' | 'center' | 'top';
24-
export type DrawerLocations = 'end' | 'start' | 'left' | 'right' | 'top' | 'bottom' | undefined;
24+
export type DrawerLocations = 'bottom' | 'end' | 'start' | 'left' | 'right' | 'top' | undefined;
2525

2626
type Height = number | string | undefined;
2727

@@ -55,6 +55,7 @@ export interface Props {
5555
resizable?: boolean | undefined;
5656
saveHeight?: boolean | undefined;
5757
saveWidth?: boolean | undefined;
58+
snapBack?: boolean | undefined;
5859
storageName?: string | undefined;
5960
storageType?: StorageType;
6061
tag?: VNavigationDrawer['tag'];
@@ -144,7 +145,7 @@ export interface UseDrawerStyles {
144145
rail?: Props['rail'],
145146
railWidth?: Props['railWidth'],
146147
resizedAmount: MaybeRef<string | number | undefined>,
147-
widthSnapBack?: Props['widthSnapBack'],
148+
snapBack?: Props['snapBack'],
148149
}
149150
): CSSProperties;
150151
}

src/plugin/utils/props.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ export const AllProps: Props = {
2020
railWidth: 8,
2121
resizable: true,
2222
saveWidth: true,
23+
snapBack: true,
2324
storageName: `${componentName}-width`,
2425
storageType: 'local',
2526
tag: 'nav',
2627
theme: undefined,
2728
touchless: false,
2829
width: 256,
29-
widthSnapBack: true,
3030
};

0 commit comments

Comments
 (0)