Skip to content

Commit be8e122

Browse files
committed
feat: 更新 dom 结构支持背景色高亮
1 parent ccf6756 commit be8e122

File tree

2 files changed

+45
-43
lines changed

2 files changed

+45
-43
lines changed

src/BootstrapBlazor/Components/TreeView/TreeView.razor

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -63,28 +63,31 @@ else
6363
@code {
6464
private RenderFragment<TreeViewItem<TItem>> RenderTreeRow => item =>
6565
@<div @key="item" class="@GetContentClassString(item)" data-bb-tree-view-index="@Rows.IndexOf(item)" @oncontextmenu="e => OnContextMenu(e, item)" @oncontextmenu:preventDefault="IsPreventDefault" @ontouchstart="e => OnTouchStart(e, item)" @ontouchend="OnTouchEnd" style="@GetTreeRowStyle(item)">
66-
<DynamicElement TagName="i" class="@GetCaretClassString(item)" TriggerClick="CanTriggerClickNode(item)" OnClick="() => OnToggleNodeAsync(item, true)"></DynamicElement>
67-
<i class="@NodeLoadingClassString"></i>
68-
@if (ShowCheckbox)
69-
{
70-
<Checkbox Value="@item" IsDisabled="GetItemDisabledState(item)"
71-
SkipValidate="true" ShowLabel="false" ShowAfterLabel="false"
72-
State="@item.CheckedState" OnStateChanged="(state, v) => OnCheckStateChanged(item, state)"
73-
OnBeforeStateChanged="@(MaxSelectedCount > 0 ? state => OnBeforeStateChangedCallback(item, state) : null)" ></Checkbox>
74-
}
75-
<DynamicElement class="@GetNodeClassString(item)" TriggerClick="TriggerNodeLabel(item)" OnClick="() => OnClick(item)">
76-
@if (ShowIcon)
77-
{
78-
<i class="@GetIconClassString(item)"></i>
79-
}
80-
@if (item.Template == null)
81-
{
82-
<span class="@GetItemTextClassString(item)">@item.Text</span>
83-
}
84-
else
66+
<div class="tree-content-header"></div>
67+
<div class="tree-content-body">
68+
<DynamicElement TagName="i" class="@GetCaretClassString(item)" TriggerClick="CanTriggerClickNode(item)" OnClick="() => OnToggleNodeAsync(item, true)"></DynamicElement>
69+
<i class="@NodeLoadingClassString"></i>
70+
@if (ShowCheckbox)
8571
{
86-
@item.Template(item.Value)
72+
<Checkbox Value="@item" IsDisabled="GetItemDisabledState(item)"
73+
SkipValidate="true" ShowLabel="false" ShowAfterLabel="false"
74+
State="@item.CheckedState" OnStateChanged="(state, v) => OnCheckStateChanged(item, state)"
75+
OnBeforeStateChanged="@(MaxSelectedCount > 0 ? state => OnBeforeStateChangedCallback(item, state) : null)" ></Checkbox>
8776
}
88-
</DynamicElement>
77+
<DynamicElement class="@GetNodeClassString(item)" TriggerClick="TriggerNodeLabel(item)" OnClick="() => OnClick(item)">
78+
@if (ShowIcon)
79+
{
80+
<i class="@GetIconClassString(item)"></i>
81+
}
82+
@if (item.Template == null)
83+
{
84+
<span class="@GetItemTextClassString(item)">@item.Text</span>
85+
}
86+
else
87+
{
88+
@item.Template(item.Value)
89+
}
90+
</DynamicElement>
91+
</div>
8992
</div>;
9093
}

src/BootstrapBlazor/Components/TreeView/TreeView.razor.scss

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,24 @@
3333
.tree-content {
3434
position: relative;
3535
display: flex;
36-
width: 100%;
36+
flex-wrap: nowrap;
3737
align-items: center;
38-
margin-inline-start: calc(var(--bb-tree-padding-left) * var(--bb-tree-view-level, 0));
3938
cursor: pointer;
4039

40+
.tree-content-header {
41+
flex-basis: calc(var(--bb-tree-padding-left) * var(--bb-tree-view-level, 0));
42+
flex-shrink: 0;
43+
}
44+
45+
.tree-content-body {
46+
display: flex;
47+
flex-wrap: nowrap;
48+
flex-grow: 1;
49+
flex-shrink: 0;
50+
align-items: center;
51+
border-radius: var(--bs-border-radius);
52+
}
53+
4154
.node-icon {
4255
width: 18px;
4356
height: 18px;
@@ -73,31 +86,21 @@
7386
}
7487
}
7588

76-
&:after {
77-
content: "";
78-
position: absolute;
79-
left: 0;
80-
right: 0;
81-
top: 0;
82-
bottom: 0;
83-
pointer-events: none;
84-
margin-inline-start: calc(var(--bb-tree-padding-left) * var(--bb-tree-view-level, 0) * -1);
85-
border-radius: var(--bb-tree-item-bg-radius);
89+
.form-check {
90+
margin: var(--bb-tree-check-margin);
8691
}
8792

8893
&:not(.disabled) {
8994
&.active {
90-
color: var(--bb-tree-item-active-color);
91-
92-
&:after {
95+
.tree-content-body {
96+
color: var(--bb-tree-item-active-color);
9397
background-color: var(--bb-tree-item-active-bg);
9498
}
9599
}
96100

97101
&:hover {
98-
color: var(--bb-tree-item-hover-color);
99-
100-
&:after {
102+
.tree-content-body {
103+
color: var(--bb-tree-item-hover-color);
101104
background-color: var(--bb-tree-item-hover-bg);
102105
}
103106
}
@@ -114,10 +117,6 @@
114117
padding: var(--bb-tree-node-padding);
115118
flex: 1;
116119

117-
.form-check {
118-
margin: var(--bb-tree-check-margin);
119-
}
120-
121120
.tree-icon {
122121
width: var(--bb-tree-icon-width);
123122
text-align: center;

0 commit comments

Comments
 (0)