Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.component.shared.HasThemeVariant;
import com.vaadin.flow.component.shared.SlotUtils;
import com.vaadin.flow.internal.JacksonUtils;
import com.vaadin.flow.internal.StateTree;
import com.vaadin.flow.shared.Registration;

Expand All @@ -54,6 +55,7 @@ public class SplitLayout extends Component
private Component secondaryComponent;
private StateTree.ExecutionRegistration updateStylesRegistration;
private Double splitterPosition;
private SplitLayoutI18n i18n;

/**
* numeration of all available orientation for VaadinSplitLayout component
Expand Down Expand Up @@ -428,4 +430,37 @@ private Double calcNewSplitterPosition(String primaryFlexBasis,
private double round(double value) {
return Math.round(value * 100.0) / 100.0;
}

/**
* Gets the internationalization object previously set for this component.
* <p>
* NOTE: Updating the instance that is returned from this method will not
* update the component if not set again using
* {@link #setI18n(SplitLayoutI18n)}.
*
* @return the i18n object or {@code null} if no i18n object has been set
* @since 25.3
*/
public SplitLayoutI18n getI18n() {
return i18n;
}

/**
* Sets the internationalization object for this component. It enables you
* to customize and translate the accessible labels used in the split
* layout.
* <p>
* Note: updating the object properties after setting the i18n will not
* update the component. To make the changes effective, you need to set the
* updated object again.
*
* @param i18n
* the i18n object, not {@code null}
* @since 25.3
*/
public void setI18n(SplitLayoutI18n i18n) {
this.i18n = Objects.requireNonNull(i18n,
"The i18n object should not be null");
getElement().setPropertyJson("i18n", JacksonUtils.beanToJson(i18n));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright 2000-2026 Vaadin Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.vaadin.flow.component.splitlayout;

import java.io.Serializable;

import com.fasterxml.jackson.annotation.JsonInclude;

/**
* The internationalization properties for {@link SplitLayout}. This can be used
* to customize and translate the accessible labels used in the split layout
* component.
*
* @see SplitLayout#setI18n(SplitLayoutI18n)
*
* @author Vaadin Ltd.
* @since 25.3
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
public class SplitLayoutI18n implements Serializable {
private String separator;

/**
* Gets the accessible label for the splitter that separates the two content
* areas.
*
* @return the accessible label for the splitter
*/
public String getSeparator() {
return separator;
}

/**
* Sets the accessible label for the splitter that separates the two content
* areas.
* <p>
* This label is used as the {@code aria-label} of the splitter, announced
* by screen readers when the splitter is focused.
*
* @param separator
* the accessible label for the splitter
* @return this instance for method chaining
*/
public SplitLayoutI18n setSeparator(String separator) {
this.separator = separator;
return this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright 2000-2026 Vaadin Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.vaadin.flow.component.splitlayout.tests;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import com.vaadin.flow.component.splitlayout.SplitLayout;
import com.vaadin.flow.component.splitlayout.SplitLayoutI18n;

class SplitLayoutI18nTest {

private SplitLayout splitLayout;
private SplitLayoutI18n i18n;

@BeforeEach
void setup() {
splitLayout = new SplitLayout();
i18n = new SplitLayoutI18n();
}

@Test
void getI18n_returnsNull() {
Assertions.assertNull(splitLayout.getI18n());
}

@Test
void setI18n_getI18n() {
splitLayout.setI18n(i18n);
Assertions.assertSame(i18n, splitLayout.getI18n());
}

@Test
void setI18n_null_throws() {
Assertions.assertThrows(NullPointerException.class,
() -> splitLayout.setI18n(null));
}

@Test
void setSeparator_getSeparator() {
Assertions.assertNull(i18n.getSeparator());
i18n.setSeparator("Resize separator");
Assertions.assertEquals("Resize separator", i18n.getSeparator());
}

@Test
void separatorSetter_returnsI18n() {
Assertions.assertSame(i18n, i18n.setSeparator("foo"));
}

@Test
void setI18n_propertySet() {
splitLayout.setI18n(i18n.setSeparator("Resize separator"));
Assertions.assertEquals("{\"separator\":\"Resize separator\"}",
splitLayout.getElement().getProperty("i18n"));
}
}
Loading