Skip to content

Commit

Permalink
Fix primefaces#11615: OutputLabel RTL support (primefaces#11616)
Browse files Browse the repository at this point in the history
  • Loading branch information
melloware committed Mar 12, 2024
1 parent 946b696 commit b96b824
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ public class OutputLabel extends OutputLabelBase {
public static final String COMPONENT_TYPE = "org.primefaces.component.OutputLabel";

public static final String STYLE_CLASS = "ui-outputlabel ui-widget";
public static final String RTL_CLASS = "ui-outputlabel-rtl";
public static final String REQUIRED_FIELD_INDICATOR_CLASS = "ui-outputlabel-rfi";
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@

import javax.faces.component.html.HtmlOutputLabel;

import org.primefaces.component.api.RTLAware;

public abstract class OutputLabelBase extends HtmlOutputLabel {

public abstract class OutputLabelBase extends HtmlOutputLabel implements RTLAware {

public static final String COMPONENT_FAMILY = "org.primefaces.component";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public void encodeEnd(FacesContext context, UIComponent component) throws IOExce

final StyleClassBuilder styleClassBuilder = getStyleClassBuilder(context)
.add(OutputLabel.STYLE_CLASS)
.add(ComponentUtils.isRTL(context, label), OutputLabel.RTL_CLASS)
.add(label.getStyleClass());

final EditableValueHolderState state = new EditableValueHolderState();
Expand Down Expand Up @@ -158,6 +159,7 @@ public void invokeContextCallback(FacesContext context, UIComponent target) {
writer.writeAttribute("class", styleClassBuilder.build(), "styleClass");
renderPassThruAttributes(context, label, HTML.LABEL_ATTRS);
renderDomEvents(context, label, HTML.LABEL_EVENTS);
renderRTLDirection(context, label);

if (!isValueBlank(_for)) {
writer.writeAttribute("for", state.getClientId(), "for");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.primefaces.component.api.AjaxSource;
import org.primefaces.component.api.ClientBehaviorRenderingMode;
import org.primefaces.component.api.MixedClientBehaviorHolder;
import org.primefaces.component.api.RTLAware;
import org.primefaces.context.PrimeApplicationContext;
import org.primefaces.context.PrimeRequestContext;
import org.primefaces.convert.ClientConverter;
Expand Down Expand Up @@ -296,6 +297,12 @@ protected void renderHiddenInput(FacesContext context, String id, String value,
writer.endElement("input");
}

public <T extends UIComponent & RTLAware> void renderRTLDirection(FacesContext context, T component) throws IOException {
if (ComponentUtils.isRTL(context, component)) {
context.getResponseWriter().writeAttribute("dir", "rtl", null);
}
}

protected String buildDomEvent(FacesContext context, UIComponent component, String domEvent, String behaviorEvent,
String behaviorEventAlias, String command) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import javax.faces.convert.ConverterException;

import org.primefaces.component.api.InputHolder;
import org.primefaces.component.api.RTLAware;
import org.primefaces.util.*;

public abstract class InputRenderer extends CoreRenderer {
Expand Down Expand Up @@ -66,12 +65,6 @@ protected boolean shouldDecode(UIInput component) {
return !isDisabled(component) && !isReadOnly(component);
}

public <T extends UIComponent & RTLAware> void renderRTLDirection(FacesContext context, T component) throws IOException {
if (ComponentUtils.isRTL(context, component)) {
context.getResponseWriter().writeAttribute("dir", "rtl", null);
}
}

/**
* Adds "aria-required" if the component is required.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,11 @@ div.ui-button, .ui-splitbutton {
margin-left: 0.4em;
}

.ui-outputlabel-rtl .ui-outputlabel-rfi {
margin-left: 0;
margin-right: 0.4em;
}

.ui-outputlabel .ui-outputlabel-label {
overflow: hidden;
}
Expand Down Expand Up @@ -1159,6 +1164,11 @@ body .ui-cascadeselect-item-content .ui-cascadeselect-group-icon {
line-height: 1;
}

.ui-float-label > label.ui-outputlabel-rtl {
left: 0;
right: 0.75rem;
}

.ui-float-label > textarea ~ label {
top: 1.2em;
}
Expand Down

0 comments on commit b96b824

Please sign in to comment.