Skip to content

Commit 65a4940

Browse files
Saracaendanharrin
andauthored
Improves sticky schema actions combined with end aligned actions (#18178)
* Width calculation of sticky actions Signed-off-by: Mark Hartman <[email protected]> * Moved the JavaScript to the right place * clean up and add negative margin to width --------- Signed-off-by: Mark Hartman <[email protected]> Co-authored-by: Dan Harrin <[email protected]>
1 parent 7bb7952 commit 65a4940

File tree

4 files changed

+54
-2
lines changed

4 files changed

+54
-2
lines changed

packages/schemas/dist/components/actions.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/schemas/dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,62 @@
11
export default () => ({
22
isSticky: false,
33

4+
width: 0,
5+
6+
resizeObserver: null,
7+
8+
boundUpdateWidth: null,
9+
10+
init() {
11+
const parent = this.$el.parentElement
12+
13+
if (!parent) {
14+
return
15+
}
16+
17+
this.updateWidth()
18+
19+
this.resizeObserver = new ResizeObserver(() => this.updateWidth())
20+
this.resizeObserver.observe(parent)
21+
22+
this.boundUpdateWidth = this.updateWidth.bind(this)
23+
window.addEventListener('resize', this.boundUpdateWidth)
24+
},
25+
426
enableSticky() {
527
this.isSticky = this.$el.getBoundingClientRect().top > 0
628
},
729

830
disableSticky() {
931
this.isSticky = false
1032
},
33+
34+
updateWidth() {
35+
const parent = this.$el.parentElement
36+
37+
if (!parent) {
38+
return
39+
}
40+
41+
const actionsComputedStyle = getComputedStyle(
42+
this.$root.querySelector('.fi-ac'),
43+
)
44+
45+
this.width =
46+
parent.offsetWidth +
47+
parseInt(actionsComputedStyle.marginInlineStart, 10) * -1 +
48+
parseInt(actionsComputedStyle.marginInlineEnd, 10) * -1
49+
},
50+
51+
destroy() {
52+
if (this.resizeObserver) {
53+
this.resizeObserver.disconnect()
54+
this.resizeObserver = null
55+
}
56+
57+
if (this.boundUpdateWidth) {
58+
window.removeEventListener('resize', this.boundUpdateWidth)
59+
this.boundUpdateWidth = null
60+
}
61+
},
1162
})

packages/schemas/resources/views/components/actions.blade.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
:actions="$actions"
5151
:alignment="$alignment"
5252
:full-width="$isFullWidth"
53+
x-bind:style="isSticky ? `width: ${width}px;` : ''"
5354
/>
5455

5556
@if ($belowContentContainer = $getChildSchema($schemaComponent::BELOW_CONTENT_SCHEMA_KEY)?->toHtmlString())

0 commit comments

Comments
 (0)