Skip to content

Improve Notices CSS layout with and without __unstableHTML #21316

@afercia

Description

@afercia

Splitting this out from #20578

The change to the notice action button (float: right added) doesn't seem ideal to me.

1
Large screen with a notice long text: position and alignments don't look so ideal:

Screenshot 2020-04-01 at 10 34 27

2
On a custom notice, it is possible to reset the default CSS classes and set custom CSS classes on the action button. See noDefaultClasses. By using className it is possible, for example, to add an is-link class to make the button look like a link. In this case, the layout doesn't look so ideal as well:

Screenshot 2020-04-01 at 10 34 30

3
By using __unstableHTML, it is possible to use HTML for the notice text. However, __unstableHTML renders an additional <div> element via the RawHTML component. This additional div breaks the flex layout:

Screenshot 2020-04-01 at 10 35 32

4
Pre-existing issue: it seems to me there's something that doesn't work as expected in the RawHTML component. To my understanding, the wrapper div should be "stripped out by the serializer unless there are non-children props passed". However, seems to me it isn't stripped out.

/**
* Component used as equivalent of Fragment with unescaped HTML, in cases where
* it is desirable to render dangerous HTML without needing a wrapper element.
* To preserve additional props, a `div` wrapper _will_ be created if any props
* aside from `children` are passed.
*
* @param {Object} props
* @param {string} props.children HTML to render.
* @param {Object} props.props Any additonal props to be set on the containing div.
*
* @return {WPComponent} Dangerously-rendering component.
*/
export default function RawHTML( { children, ...props } ) {
// The DIV wrapper will be stripped by serializer, unless there are
// non-children props present.
return createElement( 'div', {
dangerouslySetInnerHTML: { __html: children },
...props,
} );
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    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