热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Focusstylingquestion:howcanIusetheparentfocustocontrolchildelementstyling?

Justaquestionofhowtoapproachthisinaphrodite.Ihaveabutton,positionre

Just a question of how to approach this in aphrodite.

I have a button, position relative. I have a very particular looking focus rectangle; it needs to be a border that's inset a few pixels. To accomplish this i make a child span, positioned absolute to cover the button, with a 1px border.

I only want the span to show when the button is focused. In a css selector, I might have a rule for something like

1
.MyButton:focus .MyButton-focusRect { display: block }

.

How can I pull this off in aphrodite, without manually listening to events and tracking the focus state? This is a very common behavior and I'd prefer to avoid all of the manual state management.

Radium approaches this by using the decorator that tracks the hover/active/focus state, and provides a getState method to pull the current value (although it doesn't seem to work with focus). So I am guessing that's the only solution here with this css approach.

Is there a way to have a rule that says: "only when the root is focused, apply this style to a child element"? As far as I can tell, no. I would have to track focus state manually and when it is true, then add the styling to the span.

I can do this with an

1
:after

pseudoselector as well, but let's ignore that approach for a moment.

I can also achieve this with a css rule that is not generated by aphrodite.

该提问来源于开源项目:Khan/aphrodite

Thanks for the question! I'm going to close this out, but feel free to keep the discussion going!





   



推荐阅读
author-avatar
嘻嘻2502891803
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有