Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
Element
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
CI / CD Analytics
Repository Analytics
Value Stream Analytics
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
林焕东
Element
Commits
7a84a3e4
Commit
7a84a3e4
authored
Jul 26, 2017
by
maran
Committed by
杨奕
Aug 03, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
RadioGroup:add accessibility
parent
798bb8e7
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
90 additions
and
7 deletions
+90
-7
packages/radio/src/radio-button.vue
packages/radio/src/radio-button.vue
+11
-1
packages/radio/src/radio-group.vue
packages/radio/src/radio-group.vue
+52
-1
packages/radio/src/radio.vue
packages/radio/src/radio.vue
+14
-5
packages/theme-default/src/radio-button.css
packages/theme-default/src/radio-button.css
+6
-0
packages/theme-default/src/radio.css
packages/theme-default/src/radio.css
+7
-0
No files found.
packages/radio/src/radio-button.vue
View file @
7a84a3e4
...
@@ -6,6 +6,11 @@
...
@@ -6,6 +6,11 @@
{ 'is-active': value === label },
{ 'is-active': value === label },
{ 'is-disabled': isDisabled }
{ 'is-disabled': isDisabled }
]"
]"
role="radio"
:aria-checked="value === label"
:aria-disabled="isDisabled"
:tabindex="tabIndex"
@keydown.space.stop.prevent="value = label"
>
>
<input
<input
class=
"el-radio-button__orig-radio"
class=
"el-radio-button__orig-radio"
...
@@ -13,7 +18,9 @@
...
@@ -13,7 +18,9 @@
type=
"radio"
type=
"radio"
v-model=
"value"
v-model=
"value"
:name=
"name"
:name=
"name"
:disabled=
"isDisabled"
>
:disabled=
"isDisabled"
tabindex=
"-1"
>
<span
class=
"el-radio-button__inner"
:style=
"value === label ? activeStyle : null"
>
<span
class=
"el-radio-button__inner"
:style=
"value === label ? activeStyle : null"
>
<slot></slot>
<slot></slot>
<template
v-if=
"!$slots.default"
>
{{
label
}}
</
template
>
<template
v-if=
"!$slots.default"
>
{{
label
}}
</
template
>
...
@@ -62,6 +69,9 @@
...
@@ -62,6 +69,9 @@
},
},
isDisabled
()
{
isDisabled
()
{
return
this
.
disabled
||
this
.
_radioGroup
.
disabled
;
return
this
.
disabled
||
this
.
_radioGroup
.
disabled
;
},
tabIndex
()
{
return
!
this
.
isDisabled
?
(
this
.
_radioGroup
?
(
this
.
value
===
this
.
label
?
0
:
-
1
)
:
0
)
:
-
1
;
}
}
}
}
};
};
...
...
packages/radio/src/radio-group.vue
View file @
7a84a3e4
<
template
>
<
template
>
<div
class=
"el-radio-group"
>
<div
class=
"el-radio-group"
role=
"radiogroup"
@
keydown=
"handleKeydown"
>
<slot></slot>
<slot></slot>
</div>
</div>
</
template
>
</
template
>
<
script
>
<
script
>
import
Emitter
from
'
element-ui/src/mixins/emitter
'
;
import
Emitter
from
'
element-ui/src/mixins/emitter
'
;
const
keyCode
=
Object
.
freeze
({
LEFT
:
37
,
UP
:
38
,
RIGHT
:
39
,
DOWN
:
40
});
export
default
{
export
default
{
name
:
'
ElRadioGroup
'
,
name
:
'
ElRadioGroup
'
,
...
@@ -20,6 +30,47 @@
...
@@ -20,6 +30,47 @@
textColor
:
String
,
textColor
:
String
,
disabled
:
Boolean
disabled
:
Boolean
},
},
mounted
()
{
// 当radioGroup没有默认选项时,第一个可以选中Tab导航
let
radios
=
this
.
$el
.
querySelectorAll
(
'
[type=radio]
'
);
if
(
!
[].
some
.
call
(
radios
,
radio
=>
radio
.
checked
))
{
this
.
$el
.
querySelectorAll
(
'
[role=radio]
'
)[
0
].
tabIndex
=
0
;
}
},
methods
:
{
handleKeydown
(
e
)
{
// 左右上下按键 可以在radio组内切换不同选项
const
target
=
e
.
target
;
const
className
=
target
.
nodeName
===
'
INPUT
'
?
'
[type=radio]
'
:
'
[role=radio]
'
;
const
radios
=
this
.
$el
.
querySelectorAll
(
className
);
const
length
=
radios
.
length
;
const
index
=
[].
indexOf
.
call
(
radios
,
target
);
const
roleRadios
=
this
.
$el
.
querySelectorAll
(
'
[role=radio]
'
);
switch
(
e
.
keyCode
)
{
case
keyCode
.
LEFT
:
case
keyCode
.
UP
:
e
.
stopPropagation
();
e
.
preventDefault
();
if
(
index
===
0
)
{
roleRadios
[
length
-
1
].
click
();
}
else
{
roleRadios
[
index
-
1
].
click
();
}
break
;
case
keyCode
.
RIGHT
:
case
keyCode
.
DOWN
:
if
(
index
===
(
length
-
1
))
{
e
.
stopPropagation
();
e
.
preventDefault
();
roleRadios
[
0
].
click
();
}
else
{
roleRadios
[
index
+
1
].
click
();
}
break
;
default
:
break
;
}
}
},
watch
:
{
watch
:
{
value
(
value
)
{
value
(
value
)
{
this
.
$emit
(
'
change
'
,
value
);
this
.
$emit
(
'
change
'
,
value
);
...
...
packages/radio/src/radio.vue
View file @
7a84a3e4
<
template
>
<
template
>
<label
class=
"el-radio"
>
<label
class=
"el-radio"
role=
"radio"
:aria-checked=
"model === label"
:aria-disabled=
"isDisabled"
:tabindex=
"tabIndex"
@
keydown.space.stop.prevent=
"model = label"
>
<span
class=
"el-radio__input"
<span
class=
"el-radio__input"
:class=
"
{
:class=
"
{
'is-disabled': isDisabled,
'is-disabled': isDisabled,
...
@@ -16,7 +23,9 @@
...
@@ -16,7 +23,9 @@
@
focus=
"focus = true"
@
focus=
"focus = true"
@
blur=
"focus = false"
@
blur=
"focus = false"
:name=
"name"
:name=
"name"
:disabled=
"isDisabled"
>
:disabled=
"isDisabled"
tabindex=
"-1"
>
</span>
</span>
<span
class=
"el-radio__label"
>
<span
class=
"el-radio__label"
>
<slot></slot>
<slot></slot>
...
@@ -46,7 +55,6 @@
...
@@ -46,7 +55,6 @@
focus
:
false
focus
:
false
};
};
},
},
computed
:
{
computed
:
{
isGroup
()
{
isGroup
()
{
let
parent
=
this
.
$parent
;
let
parent
=
this
.
$parent
;
...
@@ -60,12 +68,10 @@
...
@@ -60,12 +68,10 @@
}
}
return
false
;
return
false
;
},
},
model
:
{
model
:
{
get
()
{
get
()
{
return
this
.
isGroup
?
this
.
_radioGroup
.
value
:
this
.
value
;
return
this
.
isGroup
?
this
.
_radioGroup
.
value
:
this
.
value
;
},
},
set
(
val
)
{
set
(
val
)
{
if
(
this
.
isGroup
)
{
if
(
this
.
isGroup
)
{
this
.
dispatch
(
'
ElRadioGroup
'
,
'
input
'
,
[
val
]);
this
.
dispatch
(
'
ElRadioGroup
'
,
'
input
'
,
[
val
]);
...
@@ -79,6 +85,9 @@
...
@@ -79,6 +85,9 @@
return
this
.
isGroup
return
this
.
isGroup
?
this
.
_radioGroup
.
disabled
||
this
.
disabled
?
this
.
_radioGroup
.
disabled
||
this
.
disabled
:
this
.
disabled
;
:
this
.
disabled
;
},
tabIndex
()
{
return
!
this
.
isDisabled
?
(
this
.
isGroup
?
(
this
.
model
===
this
.
label
?
0
:
-
1
)
:
0
)
:
-
1
;
}
}
}
}
};
};
...
...
packages/theme-default/src/radio-button.css
View file @
7a84a3e4
...
@@ -75,6 +75,12 @@
...
@@ -75,6 +75,12 @@
box-shadow
:
none
!important
;
box-shadow
:
none
!important
;
}
}
}
}
&
:focus
{
outline
:
none
;
.el-radio-button__inner
{
/*获得焦点时 样式提醒*/
box-shadow
:
0
0
1px
1px
var
(
--radio-button-checked-border-color
)
!important
;
}
}
&
:last-child
{
&
:last-child
{
.el-radio-button__inner
{
.el-radio-button__inner
{
border-radius
:
0
var
(
--border-radius-base
)
var
(
--border-radius-base
)
0
;
border-radius
:
0
var
(
--border-radius-base
)
var
(
--border-radius-base
)
0
;
...
...
packages/theme-default/src/radio.css
View file @
7a84a3e4
...
@@ -11,6 +11,13 @@
...
@@ -11,6 +11,13 @@
white-space
:
nowrap
;
white-space
:
nowrap
;
@utils-user-select
none;
@utils-user-select
none;
&:focus
{
/*获得焦点时 样式提醒*/
outline
:
none
;
.el-radio__inner
{
box-shadow
:
0
0
1px
1px
var
(
--radio-input-border-color-hover
);
}
}
&
+
.el-radio
{
&
+
.el-radio
{
margin-left
:
15px
;
margin-left
:
15px
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment