Skip to content

Commit 210c3e2

Browse files
Merge pull request #20 from CodeWithDennis/feature/add-direction-option
Added `direction` option
2 parents 30e44aa + 3094f5e commit 210c3e2

File tree

5 files changed

+24
-4
lines changed

5 files changed

+24
-4
lines changed

README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,12 @@ SelectTree::make('category_id')
6262
// Expand the tree with selected values
6363
->expandSelected(false)
6464

65-
// All groups will be opened to this level
65+
// All groups will be opened to this level
6666
->defaultOpenLevel(2)
6767

68+
// Specify the list's force direction. Options include: auto (default), top, and bottom.
69+
->directon('top')
70+
6871
// Display individual leaf nodes instead of the main group when all leaf nodes are selected
6972
->grouped(false)
7073

resources/dist/tree.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resources/js/index.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ export default function tree(
1818
emptyText,
1919
expandSelected = true,
2020
grouped = true,
21-
openLevel = 0
21+
openLevel = 0,
22+
direction = 'auto'
2223
}) {
2324
return {
2425
state,
@@ -43,7 +44,8 @@ export default function tree(
4344
emptyText,
4445
expandSelected,
4546
grouped,
46-
openLevel
47+
openLevel,
48+
direction
4749
});
4850

4951
this.tree.srcElement.addEventListener('input', (e) => {

resources/views/select-tree.blade.php

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
expandSelected: '{{ $getExpandSelected() }}',
3030
grouped: '{{ $getGrouped() }}',
3131
openLevel: '{{ $getDefaultOpenLevel() }}',
32+
direction: '{{ $getDirection() }}',
3233
})"
3334
>
3435
<div x-ref="tree"></div>

src/SelectTree.php

+14
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ class SelectTree extends Field
4747

4848
protected Closure|int $defaultOpenLevel;
4949

50+
protected string $direction = 'auto';
51+
5052
protected function setUp(): void
5153
{
5254
// Load the state from relationships using a callback function.
@@ -127,6 +129,13 @@ public function withCount(bool $withCount = true): static
127129
return $this;
128130
}
129131

132+
public function direction(string $direction): static
133+
{
134+
$this->direction = $direction;
135+
136+
return $this;
137+
}
138+
130139
public function getRelationship(): BelongsToMany|BelongsTo
131140
{
132141
return $this->getModelInstance()->{$this->evaluate($this->relationship)}();
@@ -252,4 +261,9 @@ public function getEmptyLabel(): string
252261
{
253262
return $this->emptyLabel ? $this->evaluate($this->emptyLabel) : __('No results found');
254263
}
264+
265+
public function getDirection(): string
266+
{
267+
return $this->evaluate($this->direction);
268+
}
255269
}

0 commit comments

Comments
 (0)