Skip to content

Commit be28ce3

Browse files
web-padawanclaude
andauthored
feat: add SplitLayoutI18n for customizing split-layout separator label (#9694)
## Description Part of vaadin/web-components#951 ## Type of change - Feature Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 8af860a commit be28ce3

3 files changed

Lines changed: 167 additions & 0 deletions

File tree

vaadin-split-layout-flow-parent/vaadin-split-layout-flow/src/main/java/com/vaadin/flow/component/splitlayout/SplitLayout.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import com.vaadin.flow.component.html.Div;
3434
import com.vaadin.flow.component.shared.HasThemeVariant;
3535
import com.vaadin.flow.component.shared.SlotUtils;
36+
import com.vaadin.flow.internal.JacksonUtils;
3637
import com.vaadin.flow.internal.StateTree;
3738
import com.vaadin.flow.shared.Registration;
3839

@@ -54,6 +55,7 @@ public class SplitLayout extends Component
5455
private Component secondaryComponent;
5556
private StateTree.ExecutionRegistration updateStylesRegistration;
5657
private Double splitterPosition;
58+
private SplitLayoutI18n i18n;
5759

5860
/**
5961
* numeration of all available orientation for VaadinSplitLayout component
@@ -428,4 +430,37 @@ private Double calcNewSplitterPosition(String primaryFlexBasis,
428430
private double round(double value) {
429431
return Math.round(value * 100.0) / 100.0;
430432
}
433+
434+
/**
435+
* Gets the internationalization object previously set for this component.
436+
* <p>
437+
* NOTE: Updating the instance that is returned from this method will not
438+
* update the component if not set again using
439+
* {@link #setI18n(SplitLayoutI18n)}.
440+
*
441+
* @return the i18n object or {@code null} if no i18n object has been set
442+
* @since 25.3
443+
*/
444+
public SplitLayoutI18n getI18n() {
445+
return i18n;
446+
}
447+
448+
/**
449+
* Sets the internationalization object for this component. It enables you
450+
* to customize and translate the accessible labels used in the split
451+
* layout.
452+
* <p>
453+
* Note: updating the object properties after setting the i18n will not
454+
* update the component. To make the changes effective, you need to set the
455+
* updated object again.
456+
*
457+
* @param i18n
458+
* the i18n object, not {@code null}
459+
* @since 25.3
460+
*/
461+
public void setI18n(SplitLayoutI18n i18n) {
462+
this.i18n = Objects.requireNonNull(i18n,
463+
"The i18n object should not be null");
464+
getElement().setPropertyJson("i18n", JacksonUtils.beanToJson(i18n));
465+
}
431466
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright 2000-2026 Vaadin Ltd.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
* use this file except in compliance with the License. You may obtain a copy of
6+
* the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
package com.vaadin.flow.component.splitlayout;
17+
18+
import java.io.Serializable;
19+
20+
import com.fasterxml.jackson.annotation.JsonInclude;
21+
22+
/**
23+
* The internationalization properties for {@link SplitLayout}. This can be used
24+
* to customize and translate the accessible labels used in the split layout
25+
* component.
26+
*
27+
* @see SplitLayout#setI18n(SplitLayoutI18n)
28+
*
29+
* @author Vaadin Ltd.
30+
* @since 25.3
31+
*/
32+
@JsonInclude(JsonInclude.Include.NON_NULL)
33+
public class SplitLayoutI18n implements Serializable {
34+
private String separator;
35+
36+
/**
37+
* Gets the accessible label for the splitter that separates the two content
38+
* areas.
39+
*
40+
* @return the accessible label for the splitter
41+
*/
42+
public String getSeparator() {
43+
return separator;
44+
}
45+
46+
/**
47+
* Sets the accessible label for the splitter that separates the two content
48+
* areas.
49+
* <p>
50+
* This label is used as the {@code aria-label} of the splitter, announced
51+
* by screen readers when the splitter is focused.
52+
*
53+
* @param separator
54+
* the accessible label for the splitter
55+
* @return this instance for method chaining
56+
*/
57+
public SplitLayoutI18n setSeparator(String separator) {
58+
this.separator = separator;
59+
return this;
60+
}
61+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Copyright 2000-2026 Vaadin Ltd.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
* use this file except in compliance with the License. You may obtain a copy of
6+
* the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
package com.vaadin.flow.component.splitlayout.tests;
17+
18+
import org.junit.jupiter.api.Assertions;
19+
import org.junit.jupiter.api.BeforeEach;
20+
import org.junit.jupiter.api.Test;
21+
22+
import com.vaadin.flow.component.splitlayout.SplitLayout;
23+
import com.vaadin.flow.component.splitlayout.SplitLayoutI18n;
24+
25+
class SplitLayoutI18nTest {
26+
27+
private SplitLayout splitLayout;
28+
private SplitLayoutI18n i18n;
29+
30+
@BeforeEach
31+
void setup() {
32+
splitLayout = new SplitLayout();
33+
i18n = new SplitLayoutI18n();
34+
}
35+
36+
@Test
37+
void getI18n_returnsNull() {
38+
Assertions.assertNull(splitLayout.getI18n());
39+
}
40+
41+
@Test
42+
void setI18n_getI18n() {
43+
splitLayout.setI18n(i18n);
44+
Assertions.assertSame(i18n, splitLayout.getI18n());
45+
}
46+
47+
@Test
48+
void setI18n_null_throws() {
49+
Assertions.assertThrows(NullPointerException.class,
50+
() -> splitLayout.setI18n(null));
51+
}
52+
53+
@Test
54+
void setSeparator_getSeparator() {
55+
Assertions.assertNull(i18n.getSeparator());
56+
i18n.setSeparator("Resize separator");
57+
Assertions.assertEquals("Resize separator", i18n.getSeparator());
58+
}
59+
60+
@Test
61+
void separatorSetter_returnsI18n() {
62+
Assertions.assertSame(i18n, i18n.setSeparator("foo"));
63+
}
64+
65+
@Test
66+
void setI18n_propertySet() {
67+
splitLayout.setI18n(i18n.setSeparator("Resize separator"));
68+
Assertions.assertEquals("{\"separator\":\"Resize separator\"}",
69+
splitLayout.getElement().getProperty("i18n"));
70+
}
71+
}

0 commit comments

Comments
 (0)