Skip to content

[Feature]: Auto mirror icons in Fluent UI 9/react-icons 2 #25624

Description

@NotWoods

Library

React Components / v9 (@fluentui/react-components)

Describe the feature that you would like added

It would be great to have a utility to mirror icons in RTL languages automatically. Icons like PanelLeftExpand currently need to be swapped to the equivalent PanelRightExpand manually, or have CSS applied to mirror it manually.

This can be implemented with a simple utility like bundleIcon:

const useMirrorIconStyles = makeStyles({
  mirror: { transform: 'scaleX(-1)' }
});

export function autoMirrorIcon(Icon: React.FC<FluentIconsProps>): React.FC<FluentIconsProps> {
  return (props) => {
    const { dir } = useFluent();
    const classes = useMirrorIconStyles();

    return <Icon {...props} className={mergeClasses(dir === 'rtl' && classes.mirror, props.className)} />;
  };
}

@fluentui/react-icons alternative

Alternatively, this could be done automatically as all the mirror-able icons are listed in rtl.txt.

@fluentui/react-icons could automatically apply the mirroring CSS shown above to those icons. It can either check for the [dir="rtl"] attribute or depend on @fluentui/react-shared-contexts.

That matches behaviour on Android, where the icons are marked with android:autoMirrored so Android will flip them.

Have you discussed this feature with our team

Paul Gildea

Additional context

No response

Validations

  • Check that there isn't already an issue that request the same feature to avoid creating a duplicate.

Metadata

Metadata

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions