Skip to content

Commit 2a3b5d8

Browse files
authored
Merge pull request #222 from anmcgrath/fix-select-and-text-wrap-styling
Fix select and text wrap styling
2 parents beb5af2 + 810a101 commit 2a3b5d8

File tree

7 files changed

+69
-42
lines changed

7 files changed

+69
-42
lines changed

src/BlazorDatasheet/Edit/DefaultComponents/SelectEditorComponent.razor

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77

88
<input @bind="CurrentValue"
99
@bind:event="oninput"
10-
class="text-input"
10+
class="bds-select-text-input"
1111
style="@Style; width: @(CellWidth - 2)px; height: @(CellHeight - 2)px;"
1212
@ref="InputRef"/>
13-
<div class="select-list">
13+
<div class="bds-select-list">
1414
@foreach (var val in _values)
1515
{
16-
<div class="select-item @(val.Equals(_currentSelected) ? "active" : "")"
16+
<div class="bds-select-item @(val.Equals(_currentSelected) ? "active" : "")"
1717
@onmouseup="() => SelectItem(val)">
1818
@val
1919
</div>
Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +0,0 @@
1-
.text-input {
2-
width: 100%;
3-
border: none;
4-
height: 100%;
5-
box-sizing: border-box;
6-
}
7-
8-
.text-input:focus {
9-
outline: none;
10-
}
11-
12-
.select-list {
13-
min-width: 10rem;
14-
z-index: 4;
15-
border: var(--sheet-border-style);
16-
background: var(--sheet-bg-color);
17-
position: absolute;
18-
overflow-y: auto;
19-
color: var(--sheet-foreground-color);
20-
display: block;
21-
max-height: 7rem;
22-
border-radius: 4px;
23-
}
24-
25-
.select-item {
26-
cursor: pointer;
27-
padding: 0.1rem 0.1rem 0.1rem 0.2rem;
28-
}
29-
30-
.select-item:hover,
31-
.select-item.active {
32-
background: var(--selection-bg-color)
33-
}

src/BlazorDatasheet/Render/DefaultComponents/SelectRenderer.razor

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@
44

55
<div
66
class="sheet-select-render"
7-
style="display: flex; flex-direction: row; justify-content: space-between; width:@(Cell.Width)px; height: @(Cell.Height)px">
8-
<div style="overflow: hidden;">
7+
style="display: flex;
8+
flex-direction: row;
9+
width:100%;
10+
height: 100%;">
11+
<div style="overflow: hidden; text-align: inherit; flex-shrink: 0; flex-grow: 1;">
912
@(Cell.Value?.ToString())
1013
</div>
11-
<div style="margin-right: 8px;">
14+
<div style="margin-right: 0; width: 16px;">
1215
<CaretButton OnPress="@BeginEdit"/>
1316
</div>
1417
</div>

src/BlazorDatasheet/Render/VisualCell.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ private static string GetCellFormatStyleString(int row, int col, CellFormat? for
149149
sb.AddStyle("align-items", "center");
150150
}
151151

152-
else if (format.TextWrap == TextWrapping.Wrap)
152+
if (format.TextWrap == TextWrapping.Wrap)
153153
{
154154
sb.AddStyle("text-wrap", "wrap");
155155
}

src/BlazorDatasheet/Util/StyleBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ namespace BlazorDatasheet.Util;
44

55
public class StyleBuilder
66
{
7-
private StringBuilder _stringBuilder;
7+
private readonly StringBuilder _stringBuilder;
88

99
public StyleBuilder()
1010
{

src/BlazorDatasheet/wwwroot/sheet-styles.css

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,4 +319,38 @@
319319

320320
.bds-sheet-dropper:hover{
321321
background: var(--selection-bg-color);
322-
}
322+
}
323+
324+
.bds-select-text-input {
325+
width: 100%;
326+
border: none;
327+
height: 100%;
328+
box-sizing: border-box;
329+
}
330+
331+
.bds-select-text-input:focus {
332+
outline: none;
333+
}
334+
335+
.bds-select-list {
336+
min-width: 10rem;
337+
z-index: 4;
338+
border: var(--sheet-border-style);
339+
background: var(--sheet-bg-color);
340+
position: absolute;
341+
overflow-y: auto;
342+
color: var(--sheet-foreground-color);
343+
display: block;
344+
max-height: 7rem;
345+
border-radius: 4px;
346+
}
347+
348+
.bds-select-item {
349+
cursor: pointer;
350+
padding: 0.1rem 0.1rem 0.1rem 0.4rem;
351+
}
352+
353+
.bds-select-item:hover,
354+
.bds-select-item.active {
355+
background: var(--selection-bg-color)
356+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using BlazorDatasheet.Core.Data;
2+
using BlazorDatasheet.Core.Formats;
3+
using BlazorDatasheet.Render;
4+
using FluentAssertions;
5+
using NUnit.Framework;
6+
7+
namespace BlazorDatasheet.Test.Render;
8+
9+
public class VisualCellTests
10+
{
11+
[Test]
12+
public void Text_Wrap_Appears_With_Vertical_Format_Set()
13+
{
14+
var sheet = new Sheet(10, 10);
15+
sheet.Cells["A1"]!.Format = new CellFormat()
16+
{
17+
VerticalTextAlign = TextAlign.Center,
18+
TextWrap = TextWrapping.Wrap
19+
};
20+
var vc = new VisualCell(0, 0, sheet, 12);
21+
vc.FormatStyleString.Should().Contain("text-wrap");
22+
}
23+
}

0 commit comments

Comments
 (0)